gpt4 book ai didi

java - Gradle 构建在不同的 ProductFlavors 上失败

转载 作者:行者123 更新时间:2023-12-01 09:49:39 28 4
gpt4 key购买 nike

我正在开发一个具有以下两种风格的应用程序:

productFlavors {
free {
applicationId "com.udacity.gradle.builditbigger.free"
versionName "1.0-free"
}
paid {
applicationId "com.udacity.gradle.builditbigger.paid"
versionName "1.0-paid"
}
}

现在我对免费版本有 admob 依赖项,并且希望使付费版本完全无广告,因此决定仅编译免费版本的依赖项。我尝试这样做:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":showmessage")
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:23.1.0'
freeCompile 'com.google.android.gms:play-services-ads:8.4.0'}

当我尝试调用 gradle 任务 installPaidDebug 时,它给出以下错误:

/home/hemal/Desktop/Udacity-android-nd/Build It Bigger/app/build/intermediates/manifests/full/paid/debug/AndroidManifest.xml Error:(33, 28) No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version'). Error:Execution failed for task ':app:processPaidDebugResources'. com.android.ide.common.process.ProcessException: Failed to execute aapt

但是当我简单添加以下行时:编译“com.google.android.gms:play-services-ads:8.4.0”该项目是无缝构建的。

如何克服这个问题?

最佳答案

正如评论中提到的,您需要将元数据标记从 src/main 目录中的 list 移动到 src/free 目录中的 list 。

<!-- This meta-data tag is required to use Google Play Services. --> 
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

您的免费 list 将类似于:

 <?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.udacity.gradle.builditbigger" >


<!-- Include required permissions for Google Mobile Ads to run -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


<!-- This meta-data tag is required to use Google Play Services. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />


<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Include the AdActivity configChanges and theme. -->
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</application>


</manifest>

关于java - Gradle 构建在不同的 ProductFlavors 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37683938/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com