[英]Error with google_play_services_version value from aar library
I have library and project which depends on that library. 我有依赖于该库的库和项目。 Library is stored in my private maven repo as aar file.
库存储在我的私有maven仓库中作为aar文件。 Library has different dependencies and one of them is google maps.
库有不同的依赖关系,其中一个是谷歌地图。 So I specified it in build.gradle file and set meta-data tag inside lib manifest as
所以我在build.gradle文件中指定了它,并在lib manifest中设置了meta-data标签
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
When I try to compile my project there is an error 当我尝试编译我的项目时出现错误
No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version')
找不到与给定名称匹配的资源('value'的值为'@ integer / google_play_services_version')
This is common error but I never saw problem as I described with aar file. 这是常见的错误,但我从来没有看到问题,因为我用aar文件描述。
My lib build.gradle file 我的lib build.gradle文件
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def packageName = 'com.myapplib'
def libraryVersion = '1.0.3'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
publishNonDefault true
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
}
buildTypes {
def BOOLEAN = "boolean"
def TRUE = "true"
def FALSE = "false"
def LOG_HTTP_REQUESTS = "LOG_HTTP_REQUESTS"
def LOG_IMAGES_REQUESTS = "LOG_IMAGES_REQUESTS"
def REPORT_CRASHES = "REPORT_CRASHES"
def TRACK_GTM = "TRACK_GTM"
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
buildConfigField BOOLEAN, LOG_IMAGES_REQUESTS, FALSE
buildConfigField BOOLEAN, LOG_HTTP_REQUESTS, FALSE
buildConfigField BOOLEAN, TRACK_GTM, TRUE
buildConfigField BOOLEAN, LOG_ERRORS_WITH_GTM, TRUE
buildConfigField BOOLEAN, REPORT_CRASHES, TRUE
}
debug {
ext.enableCrashlytics = false
buildConfigField BOOLEAN, LOG_IMAGES_REQUESTS, TRUE
buildConfigField BOOLEAN, LOG_HTTP_REQUESTS, TRUE
buildConfigField BOOLEAN, TRACK_GTM, FALSE
buildConfigField BOOLEAN, LOG_ERRORS_WITH_GTM, FALSE
buildConfigField BOOLEAN, REPORT_CRASHES, FALSE
}
}
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.1'
compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') {
transitive = true;
}
compile 'com.android.support:support-v4:22.1.+'
//Explicitly specified maps version
compile('com.google.android.gms:play-services-maps:7.5.0@aar') {
transitive = true;
}
}
publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
artifactId project.getName()
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
}
}
}
artifactory {
contextUrl = 'http://myapp.com/artifactory'
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'libs-release-local'
username = "admin"
password = "password"
}
defaults {
// Tell the Artifactory Plugin which artifacts should be published to Artifactory.
publications('aar')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
lib Manifest lib清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapplib"
android:versionCode="4"
android:versionName="1.0.3">
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name="com.myapplib.app.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_logo"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.myapplib.gui.LaunchActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.myapplib.gui.LandingPageActivity"
android:noHistory="true"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.myapplib.gui.PreferenceActivity"
android:noHistory="true"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
My project Manifest 我的项目清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp"
android:versionCode="8"
android:versionName="1.0.7">
<application
android:name="com.myapp.app.MyApplication"
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"
tools:replace="icon">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_api_key" />
<meta-data
android:name="com.crashlytics.ApiKey"
android:value="${crashlytics-api-key}" />
</application>
</manifest>
my app build.gradle 我的app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
}
}
dependencies {
compile(group: 'com.myapplib', name: 'myapplib', version: '1.0.3', ext: 'aar')
}
So main logic is inside library. 所以主要逻辑是在库内。 Project just have some style changes.
项目只是有一些风格变化。 As I can see inside aar file there is R.txt file with all values and params from library and also there is line
正如我在aar文件中看到的那样,R.txt文件包含来自库的所有值和参数,并且还有行
int integer google_play_services_version 0x7f080002
int integer google_play_services_version 0x7f080002
but anyway everytime when I'm compiling project I'm getting error. 但无论如何,每当我编译项目时,我都会收到错误。 How can I solve this?
我怎么解决这个问题?
One easiest and bad solution is to hardcode this value inside my library, but I think it's awful. 一个最简单和最糟糕的解决方案是在我的库中硬编码这个值,但我认为这很糟糕。
Another big question is why do I need to specify inside my manifest value from library, which uses only inside that library? 另一个重要的问题是为什么我需要在库中指定我的清单值,它只在库中使用? Why just don't use it inside and leave developes without that problem
为什么不在内部使用它并在没有这个问题的情况下离开开发
I think it is not honoring the play resources, because you don't have transient dependencies on you aar. 我认为它并不尊重游戏资源,因为你没有对你的瞬态依赖。 You are importing your own
aar
with the artifact only notation ( see Section 52.4.1.2 ). 您正在使用仅工件符号导入您自己的
aar
( 参见第52.4.1.2节 )。 If you want the dependencies to be transitive you have to explicitly set them to be so (as you did in your library build file. 如果您希望依赖项是可传递的,则必须将它们显式设置为如此(就像在库构建文件中所做的那样)。
dependencies {
compile(group: 'com.myapplib', name: 'myapplib', version: '1.0.3', ext: 'aar') {
transitive = true;
}
}
Try to add 尝试添加
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
into your main manifest file 进入主清单文件
May be library not work properly. Try to add your library from extras/google/google_play_services again and then add in your manifest file May be help this one :
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
But you didn't mention google play services version. 但你没有提到谷歌播放服务版本。 create an xml file (ie version.xml)
创建一个xml文件(即version.xml)
<?xml version ="1.0" encoding = "utf-8"?>
<resources>
<integer name ="google_play_services_version">your_version_here</integer>
</resources>
also add 还添加
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
in your manifest file. 在您的清单文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.