简体   繁体   中英

How to generate BuildConfig.DEBUG?

Using an IDE like Eclipse, IntelliJ, Studio, the class BuildConfig is auto generated in the gen folder. But what if you are using makefiles; not using an IDE? Can any of the build tools auto generate this?

When I tried to add android:debuggable attribute to my AndroidManifest.xml as described in the link below, I got a compiler error that it could not find the field.

http://developer.android.com/tools/publishing/preparing.html

Turn off logging and debugging

Make sure you deactivate logging and disable the debugging option before you build your application for release. You can deactivate logging by removing calls to Log methods in your source files. You can disable debugging by removing the android:debuggable attribute from the tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file . Also, remove any log files or static test files that were created in your project.

Yes, the build tools from command can generate BuildConfig.java file for you.

1.create project in command

$ android create project -t android-21 -p . -n AntTest --package com.example.test -a StartupActivity

2.create the makefile

release:
    @ant release

debug:
    @ant debug

release_install:
    @ant installr

debug_install:
    @ant installd

3.you can reference BuildConfig in your code, the build tool ant will generate BuildConfig.java for you.

After you invoke any command to build the project, you will see the file is generated gen/com/example/test/BuildConfig.java .

Additional information

BuildConfig.java is handled and generated by ant. We can see it from $ANDROID_SDK_ROOT/tools/ant/build.xml .

<echo level="info">----------</echo>
<echo level="info">Handling BuildConfig class...</echo>
<buildconfig
        genFolder="${gen.absolute.dir}"
        package="${project.app.package}"
        buildType="${build.is.packaging.debug}"
        previousBuildType="${build.last.is.packaging.debug}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM