質問

I'm looking for a simple way to make sure my static final boolean DEBUG flag is set to false when exporting my Android project to APK.

I've tried using the "STOPSHIP" comment marker mentioned here, but it doesn't seem to have any effect on apk export, or I'm using it wrong.

Building a lint extension seem an overkill for such purpose, is there a simpler way to do it?

Edit

Using the auto generated BuildConfig.DEBUG flag, combined with some hard to miss on-screen indication that you're running in debug mode (plus a mental note never to upload apk's at 4am after a quick fix) - will probably have you covered.
BUT it is still not the 100% fool proof method I posted this question for.

There are still complaints about BuildConfig.DEBUG randomly not functioning as expected. So This question is still open - is there a lint trick, or similar trick to do it?

役に立ちましたか?

解決 3

I've been using this flag reliably for several years now:

BuildConfig.DEBUG

It doesn't have the issues that occurred long ago, when I posted this question.

他のヒント

Starting from Android Gradle Plugin 3.0 you can make following configuration in build.gradle file:


    android { 
        lintOptions {
            fatal 'StopShip' 
        } 
    }

This will break the build as long as there exists a StopShip comment in codebase.

Watch the exact minute of Tor Norbye's "Kotlin Static Analysis with Android Lint" talk, where he talks about the feature.

Have you solved this? I know 2 years have passed, but I just found this while searching what was STOPSHIP after finding it by accident while commenting.

StopShip
--------
Summary: Code contains STOPSHIP marker

Priority: 10 / 10
Severity: Warning
Category: Correctness
NOTE: This issue is disabled by default!
You can enable it by adding --enable StopShip

So I would say you should have executed the command in order to enable it.

You could modify the build.xml, have it read your DEBUG flag from the source and simply change the file name of the APK depending on the value. Make that name explicit enough and you will never distribute or upload the wrong APK (and you can also make it a condition for other following automated processes).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top