2

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?

the_jk
  • 539
  • 2
  • 10

2 Answers2

0

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.)

Dan Schmitt
  • 126
  • 1
  • 4
  • Doesn't work for me (still complains about test/app/src/main/AndroidManifest.xml not existing) even tho buildDir is something else. gradle experimental version 0.7.2 with gradle 2.10 ? – the_jk Jun 13 '16 at 09:20
  • My test case was with the = directory being outside the project structure and existing before evaluation started. (specifically, "../../otherSource/src/main") When I point it at something like "outputs/manifest" and have task set to assemble it in that dir it fails. I've tried putting my task to do it early in the process but it balks. `project.afterEvaluate { build.dependsOn mergeManifest }` I think the file needs to exist very early, not sure how to make it happen. – Dan Schmitt Jun 14 '16 at 13:07
  • Ah, thanks for the very early comment - now I got it, making androidDebug and androidRelease depend on createManifest finally make the checkManifest task look at the right file – the_jk Jun 23 '16 at 09:27
  • I jumped a bit too early (pun not intended), seems AndroidManifest.xml must exist even earlier than that, but at least I can work around it by just running the gradle task twice now :/ – the_jk Jun 23 '16 at 09:48
0

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" ]
                }
            }
        }
    }
OlivierM
  • 2,820
  • 24
  • 41