如何解决该ProductFlavours错误

时间:2019-02-09 16:00:18

标签: android-studio

这是我第一次使用Android Studio,但无法构建此应用。 谁能告诉我如何解决此代码?

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        applicationId "org.settingsdeployer"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 4
        versionName "1.2"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        normal {
            applicationId "org.settingsdeployer"
            versionCode 4
            versionName "1.2"
        }

        french {
            applicationId "org.settingsdeployer"
            versionCode 5
            versionName "1.2_fr"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

在尝试同步时出现以下错误: 错误:现在所有调味品都必须属于命名的调味品尺寸。进一步了解https://d.android.com/r/tools/flavorDimensions-missing-error-message.html 受影响的模块:org.settingsdeployer

警告:配置'compile'已过时,并已由'implementation'和'api'代替。 它将于2018年底删除。有关更多信息,请参阅:http://d.android.com/r/tools/update-dependency-configurations.html 受影响的模块:org.settingsdeployer

我进行了请求的更改,并且已同步,但现在我无法进行apk:

那太好了,它同步了构建而没有错误,但是现在当我尝试生成apk时,我遇到了更多错误。我不知道我在做什么!


更新:

添加flavorDimensions后,它同步了构建而没有错误,但是现在当我尝试生成apk时,我得到了更多错误。我不知道我在做什么!。这是错误日志:

Executing tasks: [:org.settingsdeployer:assembleNormalRelease]

Task :org.settingsdeployer:preBuild UP-TO-DATE Task :org.settingsdeployer:preNormalReleaseBuild UP-TO-DATE Task :org.settingsdeployer:compileNormalReleaseAidl NO-SOURCE Task :org.settingsdeployer:compileNormalReleaseRenderscript UP-TO-DATE Task :org.settingsdeployer:checkNormalReleaseManifest UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseBuildConfig UP-TO-DATE Task :org.settingsdeployer:prepareLintJar UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseSources UP-TO-DATE Task :org.settingsdeployer:javaPreCompileNormalRelease UP-TO-DATE Task :org.settingsdeployer:mainApkListPersistenceNormalRelease Task :org.settingsdeployer:generateNormalReleaseResValues UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseResources UP-TO-DATE Task :org.settingsdeployer:mergeNormalReleaseResources FAILED

FAILURE: Build failed with an exception.

What went wrong: Could not resolve all files for configuration ':org.settingsdeployer:_internal_aapt2_binary'.

Could not find com.android.tools.build:aapt2:3.3.1-5013011. Searched in the following locations:

file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar Required by: project :org.settingsdeployer
Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.

1 个答案:

答案 0 :(得分:0)

  

尝试同步时出现这些错误:错误:所有口味   现在必须属于已命名的风味维度。了解更多   https://d.android.com/r/tools/flavorDimensions-missing-error-message.html   受影响的模块:org.settingsdeployer

发生了风味尺寸问题,因为尚未将flavorDimensions添加到build.gradle中。必须至少有一个flavorDimensions。像这样:

android {
    ...
    defaultConfig {...}
    buildTypes {
        debug{...}
        release{...}
    }
    // you need to specifies one flavor dimension.
    flavorDimensions "version"
    productFlavors {
        normal {
            // This property is optional if you are using only one dimension.
            dimension "version"
            applicationId "org.settingsdeployer"
            versionCode 4
            versionName "1.2"
        }
        french {
            dimension "version"
            applicationId "org.settingsdeployer"
            versionCode 5
            versionName "1.2_fr"
        }
    }
}

更多详细信息,请访问Configure build variants

  

警告:配置“编译”已过时,已被替换   与“实施”和“ API”。它将在   2018年。有关更多信息,请参阅:http://d.android.com/r/tools/update-dependency-configurations.html   受影响的模块:org.settingsdeployer

此警告表明,添加依赖项时,我们需要使用apiimplementation来替换compilation。因此,将依赖关系块更改为这样;

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:21.0.3'
}