在为版本>的设备构建Android Studio时,Android Studio无法找到资源5 [英] Android Studio cannot find resources when building for device with version > 5.0
问题描述
错误发生时,我发现了一个奇怪的行为,当我尝试为Android设备创建一个Android版本为5.0以上的棒棒糖消息是:
错误:(5,28)找不到与给定名称匹配的资源(在'versionName' @字符串/ APPLICATION_VERSION')。
消息指向我的AndroidManifest.xml文件,其中包含以下内容:
<?xml version =1.0encoding =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:
在xml布局中引用build.gradle versionName属性
您应该这样做:
android {
...
defaultConfig {
applicationIdse.test.myapp
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName1.0
}
...
applicationVariants.all {variant - >
variant.resValuestring,versionName,variant.versionName
}
...
}
I found a strange behavior with my project when I try to build it for an android device with Android version > to 5.0 (lollipop) under linux.
The error message is:
Error:(5, 28) No resource found that matches the given name (at 'versionName' with value '@string/Application_Version').
The message points to my AndroidManifest.xml file which contains this:
<?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>
When I test my application on devices below 5.1 it works as expected without any warning/error (as the string Application_Version exists and is perfectly found) but when I try a device (real or emulated) with 5.1 or greater, it throws me this message.
I updated my Android Studio to 2.3 recently and since it produces this error message. With AS 2.2 I hadn't any problem...
I already tried to fix this by doing things I found on SO with similar issues, like clean cache and restart, delete building files manually, cleaning my project using ./gradlew clean and re-importing my project but nothing seems to work until now.
Any Idea?
According to this issue: https://code.google.com/p/android/issues/detail?id=235893
You have to move versionName into app/build.gradle file. And If you want to access versionName in an xml layout file according this StackOverflow question: Reference build.gradle versionName attribute in xml layout
You should do this:
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 Studio时,Android Studio无法找到资源5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!