Android Studio 2.3:can';不要在android中使用字符串资源:versionName

Android Studio 2.3:can';不要在android中使用字符串资源:versionName,android,Android,我今天升级了AndroidStudio 2.2->2.3,现在在AndroidStudio中构建应用时出现了一个以前没有的编译器错误 Error:No resource found that matches the given name (at 'versionName' with value '@string/BRAND_VERSION'). 这是字符串资源 <string name="BRAND_VERSION">2.0</string> 这是Android示例中

我今天升级了AndroidStudio 2.2->2.3,现在在AndroidStudio中构建应用时出现了一个以前没有的编译器错误

Error:No resource found that matches the given name (at 'versionName' with value '@string/BRAND_VERSION').
这是字符串资源

<string name="BRAND_VERSION">2.0</string>
这是Android示例中的build.gradle(注意我对versionName的编辑)

}


}

升级Android Studio后,我也遇到了同样的问题。关闭instant run-in首选项有助于应用程序再次运行。

关于,此问题已被修复。这在Android studio 3.0.0-alpha6版本中提供


如果任何问题仍然存在,请报告,他们将重新打开进行检查。

只有在build.gradle构建脚本中未指定“minSdkVersion”的值时,才会使用该值。如果在gradle构建脚本中指定,则会忽略menifest值,这可能会产生误导,所以应该删除以避免歧义。发布你的
build.gradle
对我来说很好。minSdkVersion在这里有什么关系?此问题与versionName有关,仅在build.gradle中使用versionName为我复制。我从未尝试在gradle中引用字符串资源,因此,
versionName“@string/add_task”
可能出现问题并不奇怪。请注意,这是与
@string/BRAND\u VERSION
不同的字符串资源。关于清单值,但它需要一个可复制的测试用例。不幸的是,本周我无法尝试重现这个问题。如果可以的话,上传一个将问题复制到该问题的示例项目,尝试将其向前推进。哇!我无法想象这会是根本原因。我也有同样的错误,当我禁用instant run时,错误消失了。。。。谷歌方面很奇怪!
<manifest package="com.metaswitch.cp.unbrandedpackage"
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:versionCode="5"
      android:versionName="@string/BRAND_VERSION">
// versionName "1.0"
versionName "@string/add_task"
apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.example.android.architecture.blueprints.todomvploaders"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    // I really want to use a string resource here!
    // versionName "1.0"
    versionName "@string/add_task"

    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}

buildTypes {
    debug {
        minifyEnabled true
        // Uses new built-in shrinker http://tools.android.com/tech-docs/new-build-system/built-in-shrinker
        useProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
    }

    release {
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
    }
}

// If you need to add more flavors, consider using flavor dimensions.
productFlavors {
    mock {
        applicationIdSuffix = ".mock"
    }
    prod {

    }
}

// Remove mockRelease as it's not needed.
android.variantFilter { variant ->
    if(variant.buildType.name.equals('release')
            && variant.getFlavors().get(0).name.equals('mock')) {
        variant.setIgnore(true);
    }
}

// Always show the result of every unit test, even if it passes.
testOptions.unitTests.all {
    testLogging {
        events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
    }
}
buildToolsVersion '25.0.0'
/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {
    // App's dependencies, including test
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
    compile "com.google.guava:guava:$rootProject.guavaVersion"
// Dependencies for local unit tests
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"

// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"

// Dependencies for Android unit tests
androidTestCompile "junit:junit:$rootProject.ext.junitVersion"
androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

// Espresso UI Testing
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion"

// Resolve conflicts between main and test APK:
androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
androidTestCompile "com.android.support:design:$rootProject.supportLibraryVersion"