繁体   English   中英

Gradle构建在不同产品上失败

[英]Gradle build failing on different productFlavors

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

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 Itger / app / build / intermediates / manifests / full / paid / debug / AndroidManifest.xml错误:(33,28)找不到与给定名称匹配的资源( (值)为“ @ integer / google_play_services_version”)。 错误:任务':app:processPaidDebugResources'的执行失败。 com.android.ide.common.process.ProcessException:无法执行aapt

但是,当我简单地添加以下行时: compile 'com.google.android.gms:play-services-ads:8.4.0'该项目将无缝构建。

我该如何克服呢?

如注释中所述,您需要将元数据标签从src / main目录中的清单移动到src / free目录中的清单。

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

您的免费清单将类似于:

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

我认为您必须使用拆分清单文件,但请注意,清单文件在构建时会合并。 您可以查看合并规则以了解更多信息

以前有同样的问题。 解决方案是清单合并。 从常见的AndroidManifest中删除元标记,并在您的免费模块中创建另一个清单,然后在此AndroidManifest中添加元标记。

问题在于构建付费版本时,清单中定义了一个meta标签(因为它是常见清单),并且没有依赖项(因为您仅在免费版本中添加了依赖项)。 因此,付费版本无法识别此元标记对应的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM