2013-10-28 55 views
2

我無法創建使用不同清單的兩種不同構建類型。即使在使用--rerun任務重新運行gradle並完全刪除build目錄之後,Android中包含的AndroidManifest也不正確。例如,我運行assembleRelease,它包含ReleasePlus構建類型中的AndroidManifest。我想保持項目結構不需要切換到新的src // *結構。我也嘗試過使用產品風味,但是如果不改變結構,這似乎不是一種可能。導入的Eclipse項目 - 具有不同AndroidManifest的Gradle構建類型

的build.gradle:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:0.6.+' 
    } 
} 
apply plugin: 'android' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar') 
} 

android { 
    compileSdkVersion 18 
    buildToolsVersion "17.0.0" 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
      java.srcDirs = ['src'] 
      resources.srcDirs = ['src'] 
      aidl.srcDirs = ['src'] 
      renderscript.srcDirs = ['src'] 
      res.srcDirs = ['res'] 
      assets.srcDirs = ['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') 
    } 

    signingConfigs { 
     myConfig { 
      storeFile file("app.keystore") 
      ... 
     } 
    } 

    buildTypes { 
     release { 
      runProguard true 
      proguardFile 'proguard.flags' 
      signingConfig signingConfigs.myConfig 
      buildConfig 'public final static boolean PLUS = false; public final static String PROVIDER_AUTHORITY = "com.app.settings";' 
     } 
     debug { 
      buildConfig 'public final static boolean PLUS = false; public final static String PROVIDER_AUTHORITY = "com.app.settings";' 
     } 
     debugPlus.initWith(buildTypes.debug) 
     debugPlus { 
      packageNameSuffix '.plus' 
      buildConfig 'public final static boolean PLUS = true; public final static String PROVIDER_AUTHORITY = "com.app.plus.settings";' 
      sourceSets { 
       main { 
        manifest.srcFile 'AndroidManifestPlus.xml' 
        java.srcDirs = ['src', 'src-plus'] 
        res.srcDirs = ['res', 'res-plus'] 
       } 
       debugPlus.setRoot('build-types/debugPlus') 
      } 
     } 
     releasePlus.initWith(buildTypes.release) 
     releasePlus { 
      packageNameSuffix '.plus' 
      buildConfig 'public final static boolean PLUS = true; public final static String PROVIDER_AUTHORITY = "com.app.plus.settings";' 
      sourceSets { 
       main { 
        manifest.srcFile 'AndroidManifestPlus.xml' 
        java.srcDirs = ['src', 'src-plus'] 
        res.srcDirs = ['res', 'res-plus'] 
       } 
       releasePlus.setRoot('build-types/releasePlus') 
      } 
     } 
    } 
} 

回答

0

嘗試使用一個結構:

android { 

    sourceSets { 
     main { 
      manifest.srcFile 'AndroidManifest.xml' 
     } 

     debug { 
      manifest.srcFile 'debug/AndroidManifest.xml' 
     } 

     release { 
      manifest.srcFile 'release/AndroidManifest.xml' 
     } 
    } 
} 

注意,這gradle這個會嘗試你的清單合併成一個,但它並不像混帳作爲動力,所以很可能您需要複製粘貼整個文件。 2可以,但應該被認爲是不好的做法。您可以從此答案中瞭解如何在AndroidManifest中自動執行更改:Replacing a string in AndroidManifest.xml for a buildvariant doesn't work for Gradle Android Plugin Version > 0.5.4

相關問題