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.
当我尝试为linux下的android设备构建这个项目时,我发现了一个奇怪的行为。
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文件:
<?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.
当我在5.1以下的设备上测试我的应用程序时,它没有任何警告/错误(因为string Application_Version存在并且完全找到),但是当我尝试使用5.1或以上的设备(真实的或仿真的)时,它会抛出这个消息。
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...
我最近将我的Android Studio更新为2.3,因为它会产生这个错误消息。对于AS 2.2我没有任何问题……
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?
任何想法?
2 个解决方案
#1
1
According to this issue: https://code.google.com/p/android/issues/detail?id=235893
根据这个问题: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 * question: Reference build.gradle versionName attribute in xml layout
你必须将versionName移动到app/build中。gradle文件。如果您希望根据*问题:引用构建来访问xml布局文件中的versionName。xml布局中的gradle versionName属性
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
}
...
}
#2
0
Well after some testings, it seems to be related to the Instant Run feature... As soon as I deactivated it, everything worked as expected.
经过一些测试,它似乎与即时运行特性有关……我一停用它,一切都如我所料。
#1
1
According to this issue: https://code.google.com/p/android/issues/detail?id=235893
根据这个问题: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 * question: Reference build.gradle versionName attribute in xml layout
你必须将versionName移动到app/build中。gradle文件。如果您希望根据*问题:引用构建来访问xml布局文件中的versionName。xml布局中的gradle versionName属性
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
}
...
}
#2
0
Well after some testings, it seems to be related to the Instant Run feature... As soon as I deactivated it, everything worked as expected.
经过一些测试,它似乎与即时运行特性有关……我一停用它,一切都如我所料。