tasks/android.py
def build(ctx, rebuild=False, race=False, major_version='7', python_runtimes='3'):
    """
    Build the android apk. If the bits to include in the build are not specified,
    the values from `invoke.yaml` will be used.

    Example invokation:
        inv android.build
    """
    # ensure BIN_PATH exists
    if not os.path.exists(BIN_PATH):
        os.makedirs(BIN_PATH)

    # put the check confs in place
    assetconfigs(ctx)

    ldflags, gcflags, env = get_build_flags(ctx, major_version=major_version, python_runtimes=python_runtimes)

    # Generating go source from templates by running go generate on ./pkg/status
    generate(ctx, mod="vendor")

    build_tags = get_default_build_tags(build="android")

    # Even though gomobile supports modules, I didn't manage to make `gomobile bind` work.
    # There are two problems: First, it calls `go list -m all` to parse the repo dependencies,
    # which doesn't work if using vendoring. This can be solved by using go modules not vendored.
    # The second problem is that it tries to import our repo as a module from generated code and
    # our repo is not importable due to the dependency on k8s.io/kubernetes. A workaround is to
    # remove the k8s dependencies from go.mod before doing the build (since they are not needed
    # for Android), but given all these problems I decided to just disable go modules.
    env["GO111MODULE"] = "off"
    # Install gomobile on the GOPATH instead of as a module
    ctx.run('go get golang.org/x/mobile/cmd/gomobile', env=env)
    # Pin its version to what's indicated in go.mod
    ctx.run(
        'VERSION=$(grep golang.org/x/mobile go.mod | rev | cut -d - -f 1 | rev); cd /go/src/golang.org/x/mobile; git checkout $VERSION'
    )

    ctx.run('go run golang.org/x/mobile/cmd/gomobile init', env=env)
    cmd = "go run golang.org/x/mobile/cmd/gomobile bind -target android {race_opt} {build_type} -tags \"{go_build_tags}\" "
    cmd += "-o {agent_bin} -gcflags=\"{gcflags}\" -ldflags=\"{ldflags}\" {REPO_PATH}/cmd/agent/android"
    args = {
        "race_opt": "-race" if race else "",
        "build_type": "-a" if rebuild else "",
        "go_build_tags": " ".join(build_tags),
        "agent_bin": os.path.join(BIN_PATH, bin_name("ddagent", android=True)),
        "gcflags": gcflags,
        "ldflags": ldflags,
        "REPO_PATH": REPO_PATH,
    }
    ctx.run(cmd.format(**args), env=env)

    pwd = os.getcwd()
    os.chdir("cmd/agent/android")
    if sys.platform == 'win32':
        cmd = "gradlew.bat --no-daemon build"
    else:
        cmd = "./gradlew --no-daemon build"
    ctx.run(cmd)
    os.chdir(pwd)
    ver = get_version(ctx, include_git=True, git_sha_length=7, major_version=major_version, include_pipeline_id=True)
    outfile = f"bin/agent/ddagent-{ver}-unsigned.apk"
    shutil.copyfile("cmd/agent/android/app/build/outputs/apk/release/app-release-unsigned.apk", outfile)

    Build the android apk. If the bits to include in the build are not specified,
    the values from `invoke.yaml` will be used.

    Example invokation:
        inv android.build
    
Build the android apk. If the bits to include in the build are not specified,
the values from `invoke.yaml` will be used.


Build the android apk . If the bits to include in the build are not specified the values from ` invoke . yaml ` will be used .
def build(ctx, rebuild=False, race=False, major_version='7', python_runtimes='3'):
    if not os.path.exists(BIN_PATH):
        os.makedirs(BIN_PATH)
    assetconfigs(ctx)
    ldflags, gcflags, env = get_build_flags(ctx, major_version=major_version, python_runtimes=python_runtimes)
    generate(ctx, mod="vendor")
    build_tags = get_default_build_tags(build="android")
    env["GO111MODULE"] = "off"
    ctx.run('go get golang.org/x/mobile/cmd/gomobile', env=env)
    ctx.run(
        'VERSION=$(grep golang.org/x/mobile go.mod | rev | cut -d - -f 1 | rev); cd /go/src/golang.org/x/mobile; git checkout $VERSION'
    )
    ctx.run('go run golang.org/x/mobile/cmd/gomobile init', env=env)
    cmd = "go run golang.org/x/mobile/cmd/gomobile bind -target android {race_opt} {build_type} -tags \"{go_build_tags}\" "
    cmd += "-o {agent_bin} -gcflags=\"{gcflags}\" -ldflags=\"{ldflags}\" {REPO_PATH}/cmd/agent/android"
    args = {
        "race_opt": "-race" if race else "",
        "build_type": "-a" if rebuild else "",
        "go_build_tags": " ".join(build_tags),
        "agent_bin": os.path.join(BIN_PATH, bin_name("ddagent", android=True)),
        "gcflags": gcflags,
        "ldflags": ldflags,
        "REPO_PATH": REPO_PATH,
    }
    ctx.run(cmd.format(**args), env=env)
    pwd = os.getcwd()
    os.chdir("cmd/agent/android")
    if sys.platform == 'win32':
        cmd = "gradlew.bat --no-daemon build"
    else:
        cmd = "./gradlew --no-daemon build"
    ctx.run(cmd)
    os.chdir(pwd)
    ver = get_version(ctx, include_git=True, git_sha_length=7, major_version=major_version, include_pipeline_id=True)
    outfile = f"bin/agent/ddagent-{ver}-unsigned.apk"
    shutil.copyfile("cmd/agent/android/app/build/outputs/apk/release/app-release-unsigned.apk", outfile)
def build ( ctx , rebuild = False , race = False , major_version = '7' , python_runtimes = '3' ) : if not os . path . exists ( BIN_PATH ) : os . makedirs ( BIN_PATH ) assetconfigs ( ctx ) ldflags , gcflags , env = get_build_flags ( ctx , major_version = major_version , python_runtimes = python_runtimes ) generate ( ctx , mod = "vendor" ) build_tags = get_default_build_tags ( build = "android" ) env [ "GO111MODULE" ] = "off" ctx . run ( 'go get golang.org/x/mobile/cmd/gomobile' , env = env ) ctx . run ( 'VERSION=$(grep golang.org/x/mobile go.mod | rev | cut -d - -f 1 | rev); cd /go/src/golang.org/x/mobile; git checkout $VERSION' ) ctx . run ( 'go run golang.org/x/mobile/cmd/gomobile init' , env = env ) cmd = "go run golang.org/x/mobile/cmd/gomobile bind -target android {race_opt} {build_type} -tags \"{go_build_tags}\" " cmd += "-o {agent_bin} -gcflags=\"{gcflags}\" -ldflags=\"{ldflags}\" {REPO_PATH}/cmd/agent/android" args = { "race_opt" : "-race" if race else "" , "build_type" : "-a" if rebuild else "" , "go_build_tags" : " " . join ( build_tags ) , "agent_bin" : os . path . join ( BIN_PATH , bin_name ( "ddagent" , android = True ) ) , "gcflags" : gcflags , "ldflags" : ldflags , "REPO_PATH" : REPO_PATH , } ctx . run ( cmd . format ( ** args ) , env = env ) pwd = os . getcwd ( ) os . chdir ( "cmd/agent/android" ) if sys . platform == 'win32' : cmd = "gradlew.bat --no-daemon build" else : cmd = "./gradlew --no-daemon build" ctx . run ( cmd ) os . chdir ( pwd ) ver = get_version ( ctx , include_git = True , git_sha_length = 7 , major_version = major_version , include_pipeline_id = True ) outfile = f"bin/agent/ddagent-{ver}-unsigned.apk" shutil . copyfile ( "cmd/agent/android/app/build/outputs/apk/release/app-release-unsigned.apk" , outfile )
Build the android apk.
Build the android apk .
"""
    Build the android apk. If the bits to include in the build are not specified,
    the values from `invoke.yaml` will be used.

    Example invokation:
        inv android.build
    """ # ensure BIN_PATH exists # put the check confs in place # Generating go source from templates by running go generate on ./pkg/status # Even though gomobile supports modules, I didn't manage to make `gomobile bind` work. # There are two problems: First, it calls `go list -m all` to parse the repo dependencies, # which doesn't work if using vendoring. This can be solved by using go modules not vendored. # The second problem is that it tries to import our repo as a module from generated code and # our repo is not importable due to the dependency on k8s.io/kubernetes. A workaround is to # remove the k8s dependencies from go.mod before doing the build (since they are not needed # for Android), but given all these problems I decided to just disable go modules. # Install gomobile on the GOPATH instead of as a module # Pin its version to what's indicated in go.mod
ctx
rebuild
race
major_version
python_runtimes