我有依赖于该库的库和项目。库以aar文件的形式存储在我的私有(private)Maven存储库中。图书馆有不同的依赖关系,其中之一就是谷歌 map 。所以我在build.gradle文件中指定了它,并在lib manifest中将meta-data标记设置为
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
当我尝试编译我的项目时,出现错误
这是常见的错误,但是我从未见过我用aar文件描述过的问题。
我的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 list
<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>
我的项目 list
<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>
我的应用程序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')
}
因此,主要逻辑是在库内部。项目只是有一些样式更改。正如我所看到的,在aar文件中有R.txt文件,其中包含库中的所有值和参数,并且还有一行
但是无论如何,每当我编译项目时,我都会出错。我该如何解决?
一个最简单,最糟糕的解决方案是在我的库中对这个值进行硬编码,但是我认为这很糟糕。
另一个大问题是为什么我需要在仅在该库内部使用的库的 list 值内部进行指定?为什么只在内部不使用它而使开发没有问题
最佳答案
我认为这不尊重播放资源,因为您没有暂时的依赖关系。您正在使用仅工件符号(see Section 52.4.1.2)导入自己的aar
。如果要使依赖项具有传递性,则必须明确将其设置为(如在库构建文件中所做的那样)。
dependencies {
compile(group: 'com.myapplib', name: 'myapplib', version: '1.0.3', ext: 'aar') {
transitive = true;
}
}
关于android - 来自AAR库的google_play_services_version值错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31989691/