当我尝试为Linux版本>到5.0(lollipop)的Android设备构建项目时,我的项目出现了奇怪的行为。
错误消息是:
Error:(5, 28) No resource found that matches the given name (at 'versionName' with value '@string/Application_Version').
该消息指向我的AndroidManifest.xml文件,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.testApplication"
android:versionCode="1"
android:versionName="@string/Application_Version"
split="lib_dependencies_apk">
</manifest>
当我在低于5.1的设备上测试我的应用程序时,它可以按预期运行,而没有任何警告/错误(因为字符串 Application_Version 存在并且可以完美找到),但是当我尝试使用5.1或更高版本的设备(真实的或仿真的)时这条信息。
我最近将Android Studio更新为2.3,因为它会产生此错误消息。使用AS 2.2时,我没有任何问题...
我已经尝试通过在SO上发现类似问题来解决此问题,例如清理缓存并重新启动,手动删除构建文件,使用./gradlew clean清理我的项目并重新导入我的项目,但到目前为止似乎没有任何效果。
最佳答案
根据此问题:
https://code.google.com/p/android/issues/detail?id=235893
您必须将versionName移至app / build.gradle文件。并且如果您想根据以下StackOverflow问题访问xml布局文件中的versionName:
Reference build.gradle versionName attribute in xml layout
你应该做这个:
android {
...
defaultConfig {
applicationId "se.test.myapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
...
applicationVariants.all { variant ->
variant.resValue "string", "versionName", variant.versionName
}
...
}
关于android - 为版本> 5.0的设备进行构建时,Android Studio无法找到资源,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42604987/