0

当我将 设置versionCode为 2 时,应用程序仍将其报告为 1。当我将 设置versionCode为 3 时,应用程序会检测到。alo 5, 6 但未设置:

defaultConfig {
    versionCode 2

没有使用数字 2,我已经清理了项目并重建了但仍然是相同的结果。

我错过了什么?

我想用这段 Firebase 代码检测何时发布了新的应用程序版本:请注意,我在 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) {

            }
        };

当我从 versionCode 1 到 versionCode 2 我注意到上面BuildConfig.VERSION_CODE是 1

我也试试这个:

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

还返回 1 作为 versionCode

4

3 回答 3

0

你的问题不清楚,但我会回答。您认为每个用户在发布新版本时都会更新他们的应用程序,但其中一些不会更新。旧版本用户将错误等报告为旧版本。

于 2017-05-20T15:30:05.107 回答
0

我已经检查过我们不应该在 Gradle 配置文件的内联注释中添加双引号。

例如:

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

是错误的并在代码中读取为 1(无论 BuildConfig 文件是否使用 2 正确生成),但是:

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

是正确的并在代码中读为 2

疯狂的

于 2017-11-02T12:04:17.390 回答
0

答案不是在 Build.Gradle 文件中添加注释

像这样:,当删除评论时,一切都再次按预期工作

  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
    }
于 2017-05-20T19:51:34.157 回答