簡體   English   中英

來自aar庫的google_play_services_version值出錯

[英]Error with google_play_services_version value from aar library

我有依賴於該庫的庫和項目。 庫存儲在我的私有maven倉庫中作為aar文件。 庫有不同的依賴關系,其中一個是谷歌地圖。 所以我在build.gradle文件中指定了它,並在lib manifest中設置了meta-data標簽

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

當我嘗試編譯我的項目時出現錯誤

找不到與給定名稱匹配的資源('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清單

<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>

我的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')    
}

所以主要邏輯是在庫內。 項目只是有一些風格變化。 正如我在aar文件中看到的那樣,R.txt文件包含來自庫的所有值和參數,並且還有行

int integer google_play_services_version 0x7f080002

但無論如何,每當我編譯項目時,我都會收到錯誤。 我怎么解決這個問題?
一個最簡單和最糟糕的解決方案是在我的庫中硬編碼這個值,但我認為這很糟糕。

另一個重要的問題是為什么我需要在庫中指定我的清單值,它只在庫中使用? 為什么不在內部使用它並在沒有這個問題的情況下離開開發

我認為它並不尊重游戲資源,因為你沒有對你的瞬態依賴。 您正在使用僅工件符號導入您自己的aar參見第52.4.1.2節 )。 如果您希望依賴項是可傳遞的,則必須將它們顯式設置為如此(就像在庫構建文件中所做的那樣)。

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

嘗試添加

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

進入主清單文件

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" />

但你沒有提到谷歌播放服務版本。 創建一個xml文件(即version.xml)

   <?xml version ="1.0" encoding = "utf-8"?>
   <resources>
   <integer name ="google_play_services_version">your_version_here</integer>
   </resources>

還添加

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

在您的清單文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM