How can I move the AndroidManifest.xml file with the experimental gradle plugin 0.7.x?

1k Views Asked by At

I'm trying to change the location of the AndroidManifest.xml file when using the experimental gradle plugin version 0.7.x. The reason for doing this is that I generate the file (as there is no manifest merger/property replacer in the experimental plugin) so I don't want an output file together with the sources.

My app build.gradle:

apply plugin: "com.android.model.application"

def buildDir = project.buildDir

model {
  android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
      applicationId "com.myapp.android"
      minSdkVersion.apiLevel 9
      targetSdkVersion.apiLevel 23
      versionCode 1
      versionName "1.0"
    }
    sources {
      main {
        manifest {
          source {
            srcDirs = ["$buildDir"]
          }
        }
      }
    }
  }
}

task createManifest {
  doLast {
    buildDir.mkdirs()
    new FileOutputStream(new File(buildDir, "AndroidManifest.xml"))
  }
}

tasks.all { task ->
  if (task.name.startsWith('check') && task.name.endsWith('Manifest'))     {
    task.dependsOn createManifest
  }
}

The above configures fine but when I try to build I get:

A problem was found with the configuration of task ':app:checkDebugManifest'.
> File '/home/the_jk/source/test/app/src/main/AndroidManifest.xml' specified for property 'manifest' does not exist.`

I cannot seem to change the default manifest "property" at all, anyone had any luck?

2

There are 2 best solutions below

4
On BEST ANSWER

Try

      manifest { source { srcDirs = $buildDir } }

This seems to do ok with just 1 manifest, but the experimental plugin barfs if you give it 2 directories that you want to merge.

(I'm also guessing you have some other task to generate the manifest in the $buildDir since that gets blown away by clean tasks....)

Update:

Secondary issue, the check[Deubg|Release]Manifest task wants the file to exist when it runs. The above works ok for me for a static file. For something generated from a task in the build directory I had to add a dependency that looks like

task createManifest {
         // code to create $buildDir if it did not exist
         // code to generate AndrdroidManfest.xml in $buildDir
}

tasks.all {
    task ->
       if (task.name.startsWith('check') && task.name.endsWith('Manifest')) {
           task.dependsOn createManifest
       }
}

The tasks.all loop lets me only add it if checkDebugManifest and/or checkReleaseManifest tasks are going to happen (I had trouble with ./gradlew clean not finding the checkDebugManifest task without it.)

2
On

I had a similar issue with com.android.tools.build:gradle-experimental:0.7.0-alpha4. The way I solve it was with the following code:

    sources {
        main {
            manifest {
                source {
                    srcDirs = [ "$buildDir" ]
                }
            }
        }
    }