首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >aar库中的google_play_services_version值出错

aar库中的google_play_services_version值出错
EN

Stack Overflow用户
提问于 2015-08-13 21:30:07
回答 4查看 1.7K关注 0票数 16

我有依赖于这个库的库和项目。库作为aar文件存储在我的私有maven存储库中。库有不同的依赖关系,其中之一就是google地图。因此,我在build.gradle文件中指定了它,并将库清单中的元数据标记设置为

<meta-data 
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

当我尝试编译我的项目时出现错误

找不到与给定名称匹配的资源(位于' value‘,其值为'@integer/google_play_services_version')

这是一个常见的错误,但是我从来没有看到像我描述的aar文件那样的问题。

我的库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 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>

我的项目清单

<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文件,还有一行

整型google_play_services_version 0x7f080002

但不管怎样,每次当我编译项目时,我都会遇到错误。我该如何解决这个问题呢?

一个最简单也是最糟糕的解决方案是在我的库中硬编码这个值,但我认为这很糟糕。

另一个大问题是,为什么我需要在我的清单中指定来自库的值,它只在库中使用?为什么不在内部使用它,让开发人员自己解决这个问题呢

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-08-24 12:20:30

我认为它不尊重play资源,因为你对你的aar没有短暂的依赖。您正在使用纯工件表示法(see Section 52.4.1.2)导入您自己的aar。如果您希望依赖项是可传递的,则必须显式地将其设置为可传递的(就像您在库构建文件中所做的那样。

dependencies {
    compile(group: 'com.myapplib', name: 'myapplib', version: '1.0.3', ext: 'aar')  {
        transitive = true;
    }
}
票数 1
EN

Stack Overflow用户

发布于 2015-08-23 15:47:14

尝试添加

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google\_play\_services\_version" />

添加到您的主清单文件中

票数 0
EN

Stack Overflow用户

发布于 2015-08-24 13:38:14

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" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31989691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档