2017-02-17 11 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"

這種固定的生成錯誤的我,但我仍然試圖找出爲什麼在空格後的條目被忽略