0

When i set the versionCode to 2 the app still report it to be 1. When I set the versionCode to 3 the app detect that. alo 5, 6 but not setting:

defaultConfig {
    versionCode 2

Is not working with the number 2, I have cleaned the project and rebuilt but still same result.

What am I missing?

I want to detect when a new app version is released with this piece of Firebase code: Note that I run this in debug in Android Studio

ValueEventListener systemListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                App app = dataSnapshot.getValue(App.class);
                if (app.getVersionCode() > BuildConfig.VERSION_CODE) {
                    SettingsManager.setForceAppUpdate(true);
                    for (OnForceAppUpdateListener l : Application.getInstance()
                            .getUIListeners(OnForceAppUpdateListener.class))
                        l.onForceAppUpdate();
                } else { // TODO for testing
                    SettingsManager.setForceAppUpdate(false);
                    for (OnForceAppUpdateListener l : Application.getInstance()
                            .getUIListeners(OnForceAppUpdateListener.class))
                        l.onForceAppUpdate();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };

And when I went from versionCode 1 to versionCode 2 I notis the above BuildConfig.VERSION_CODE being 1

I also try this:

Application.getInstance().getPackageManager()
.getPackageInfo(Application.getInstance()
.getPackageName(), 0).versionCode;

Also return 1 for versionCode

Tord Larsen
  • 2,670
  • 8
  • 33
  • 76

3 Answers3

0

Your question not clear but I will answer. You think every user update their app when you release new version, but some of them will not update. Old version users reports errors etc. as older versions.

Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52
0

The answer for this is not to but comments in the Build.Gradle file

like this:, when removing the comments it all worked as expected again

  defaultConfig {
        applicationId "com.toy.android"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 2
        // Semantic Versioning 2.0.0 - http://semver.org/#semantic-versioning-200
        // MAJOR version when you make incompatible API changes,
        // MINOR version when you add functionality in a backwards-compatible manner, and
        // PATCH version when you make backwards-compatible bug fixes.
        versionName "0.1.1 Alpha"
        //Android Studio 1.4 introduced limited support for vector drawables by generating
        // pngs at build time. To disable this functionality (and gain the true advantage
        // and space savings of this Support Library), you need to add vectorDrawables.
        // useSupportLibrary = true to your build.gradle file:
        vectorDrawables.useSupportLibrary = true
        manifestPlaceholders = [onesignal_app_id: "2ca652bb-260d-4c33-9d5f-6569e107ed2f",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "1098805773237"]
        //multiDexEnabled true
    }
Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
0

I've checked that we shouldn't add double quotes inside inline comments in Gradle config file.

For example:

buildConfigField "int", "DATABASE_VERSION", "2"  // remember to update "repo/docs/sqlite-versions.md"

is WRONG and read as 1 in code (no matters if the BuildConfig file is generated correctly with a 2), but:

buildConfigField "int", "DATABASE_VERSION", "2"  // remember to update repo/docs/sqlite-versions.md

is CORRECT and read as 2 in code

INSANE

thelawnmowerman
  • 11,956
  • 2
  • 23
  • 36