src/main ----java/ ----res/ ----assets/ ----aidl/ ----rs/ ----jni/ ----AndroidManifest.xml src/androidTest/ ----java/
问题一、因为sourceSets配置而导致的:specified for property ‘manifest‘ does not exist.
官方的配置:
android { sourceSets { main { manifest.srcFile ‘AndroidManifest.xml‘ java.srcDirs = [‘src‘] resources.srcDirs = [‘src‘] aidl.srcDirs = [‘src‘] renderscript.srcDirs = [‘src‘] res.srcDirs = [‘res‘] assets.srcDirs = [‘assets‘] } } }
我的配置:
sourceSets { main { manifest.srcFile ‘src/main/AndroidManifest.xml‘ java.srcDirs = [‘src/main/java‘] /* resources.srcDirs = [‘src/main/res‘] aidl.srcDirs = [‘src‘] renderscript.srcDirs = [‘src‘]*/ res.srcDirs = [‘src/main/res‘] assets.srcDirs = [‘src/main/assets‘] } }
问题二、当你main版本和GooglePlay版本的Manifest配置一样时,出现:
declared at AndroidManifest.xml:157:5 Error:(3, 5) Attribute manifest@versionCode value=(12) from AndroidManifest.xml:3:5 Error:(4, 5) Attribute manifest@versionName value=(2.1) from AndroidManifest.xml:4:5 is also present at AndroidManifest.xml:4:5 value=(2.0-debug) Suggestion: add ‘tools:replace="android:versionName"‘ to <manifest> element at AndroidManifest.xml:1:1 to override :app:processGooglePlayDebugManifest FAILED Error:Execution failed for task ‘:app:processGooglePlayDebugManifest‘. > Manifest merger failed with multiple errors, see logs
解决:
1.Suggestion: add ‘tools:replace="android:versionName"‘ to <manifest> element at AndroidManife 这句话就是叫你在AndroidManifest.xml里面加这个东西,
2.网上还有种方法在build.gradle根标签上加上useOldManifestMerger true, 我试了下不行。所以只能老老实有第一种。
<manifest xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" tools:replace="android:versionName,android:versionCode"
最后上一个我自己的最终版的配置信息:
apply plugin: ‘com.android.application‘ android { compileSdkVersion 21 buildToolsVersion "21.1.1" defaultConfig { applicationId "com.deetech" minSdkVersion 8 targetSdkVersion 21 versionCode 2 versionName "2.0" // AndroidManifest.xml 里面UMENG_CHANNEL的value为 ${UMENG_CHANNEL_VALUE} // manifestPlaceholders = [UMENG_CHANNEL_VALUE: "channel_name"] } packagingOptions{ exclude ‘META-INF/NOTICE‘ exclude ‘META-INF/LICENSE‘ exclude ‘META-INF/DEPENDENCIES‘ } /* buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.txt‘ } }*/ //执行lint检查,有任何的错误或者警告提示,都会终止构建,我们可以将其关掉。 lintOptions { abortOnError false } //签名 signingConfigs { debug { storeFile file("C:/Users/Administrator/.android/debug.keystore") } relealse { storeFile file("F:/gradle.jks") //Android Studio --> Build --> Generate Signed APK --> Create New 可以生成 storePassword "gradle" //在生成.jks文件时需要填入的参数一一对应即可 keyAlias "gradle" keyPassword "gradle" } } buildTypes { debug { // 显示Log buildConfigField "boolean", "LOG_DEBUG", "true" versionNameSuffix "-debug" minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.debug } release { // 不显示Log buildConfigField "boolean", "LOG_DEBUG", "false" //混淆 minifyEnabled true //Zipalign优化 zipAlignEnabled true // 移除无用的resource文件 shrinkResources true //加载默认混淆配置文件 progudard-android.txt在sdk目录里面,不用管,proguard.cfg是我们自己配<span></span>的混淆文件 proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard.cfg‘ //签名 signingConfig signingConfigs.relealse } } sourceSets { main { manifest.srcFile ‘src/main/AndroidManifest.xml‘ java.srcDirs = [‘src/main/java‘] /* resources.srcDirs = [‘src/main/res‘] aidl.srcDirs = [‘src‘] renderscript.srcDirs = [‘src‘]*/ res.srcDirs = [‘src/main/res‘] assets.srcDirs = [‘src/main/assets‘] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot(‘tests‘) // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot(‘build-types/debug‘) release.setRoot(‘build-types/release‘) GooglePlay{ //设置GooglePlay 渠道的配置文件位置 manifest.srcFile ‘src/main/googlePlay/AndroidManifest.xml‘ } /* xiaomi { manifest.srcFile ‘AndroidManifest.xml‘ } umeng { manifest.srcFile ‘AndroidManifest.xml‘ }*/ } //渠道Flavors,我这里写了一些常用的 productFlavors { GooglePlay { //packageName="com.deetech" //这里可以配置不同的包名 } xiaomi { //packageName="com.deetech" } umeng { // packageName="com.deetech" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } /* productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }*/ //在生成的apk文件,修改下命名而已 applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) { def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk") output.outputFile = new File(outputFile.parent, fileName) } } } } dependencies { // compile ‘com.android.support:support-v4:20.0.0‘ compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) compile ‘com.google.code.gson:gson:2.2.4‘ }
原文:http://my.oschina.net/u/1995545/blog/404535