2017-02-17 333 views
1

我面对的同时编译项目多个条目相同的密钥:机器人:allowBackup = REPLACE和android1:allowBackup = REPLACE使用以下

下面是错误日志

Error:Execution failed for task ':sampleproject:processDebugAndroidTestManifest'. 
> java.lang.IllegalArgumentException: Multiple entries with same key: android:allowBackup=REPLACE and android1:allowBackup=REPLACE 

的AndroidManifest.xml

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> 

    <uses-sdk tools:overrideLibrary="com.sample.toolkit.payment"/> 

    <application 
     android:allowBackup="false" 
     android:icon="@mipmap/icn_app" 
     android:label="@string/app_name" 
     android:largeHeap="true" 
     android:supportsRtl="false" 
     android:theme="@style/MaterialTheme" 
     tools:replace="android:label, theme, allowBackup, android:icon,android:supportsRtl"> 


     <activity 
      android:name="com.sample.SwiftActivity" 
      android:screenOrientation="portrait" 
      android:theme="@style/MaterialTheme" /> 

     <activity 
      android:name="com.activities.TermsAndConditionActivity" 
      android:screenOrientation="portrait" 
      android:theme="@style/MaterialTheme" /> 


    </application> 


</manifest> 

回答

-1

试试我的插件来解决它。

Seal - A gradle plugin to do precheck of Android Manifest.

1.Compile &应用密封插件:

// project's build.gradle 
buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.1' 
     classpath 'me.xx2bab.gradle:seal-manifest-precheck-plugin:1.0.0' 
    } 
} 

... 

// app's build.gradle 
apply plugin: 'seal' 

2.Configurations:

def projectRoot = project.getRootProject().rootDir.absolutePath 

// Folders may include AndroidManifest.xml files 
// 1. For gradle plugin 2.3.0 or higher, build-cache is default choice, 
// 2. But we should make sure snapshot-libs will be checked too. 
// 3. Free to add your folders for more customization 
def manifestPath = [ 
     // for AAR of Release 
     // see note below 
     projectRoot + '/build-cache', 
     // for AAR of SNAPSHOT 
     projectRoot + '/app/build/intermediates/exploded-aar' 
] 

def removeAttrs = [ 
     'android:debuggable' 
] 

def replaceValues = [ 
     'android:allowBackup' 
] 


seal { 
    enabled = true 
    manifests = manifestPath 

    appAttrs { 
     enabled = true 
     attrsShouldRemove = removeAttrs 
    } 

    appReplaceValues { 
     enabled = true 
     valuesShouldRemove = replaceValues 
    } 
} 

3.Note:如果build-cache是启用,印章建议习惯m生成放置在项目文件夹中的缓存文件夹。

//gradle.properties 
android.buildCacheDir=./build-cache 
... 
1

尝试从tools:replace列表中删除的空间。

tools:replace="android:label,theme,allowBackup,android:icon,android:supportsRtl"

这种固定的生成错误的我,但我仍然试图找出为什么在空格后的条目被忽略