I am having a hard time removing unnecessary (permissions) stuff from my manifest file after compiling and sigining a release version of my app.
I simply don't want anything merged from other libraries's manifest files. I have my own manifest file and thats it. no other manifest should be merged in
anyone knows how to completely disable manifest merging?
Try this
android.applicationVariants.all{ variant ->
variant.outputs.each { output ->
output.processResources.manifestFile = file('AndroidManifest.xml')
output.processManifest.enabled=false
}
}
What you need to do is disable the processManifest task so that it doesn't run and tell the processResources where the manifest to use is:
android.applicationVariants.all { variant ->
variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
variant.processManifest.enabled=false
}
This should work.
Related
Gradle sync failed:
Manifest Tasks does not support the manifestOutputFile property any more, please use the manifestOutputDirectory instead.
For more information, please check
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
I opened the link and applied it but still can not solve my problem ..
it was said to add this code in build.gradle module app ..
applicationVariants.all { variant ->
variant.outputs.all { output ->
output.processManifest.doLast {
// Stores the path to the maifest.
String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
// Stores the contents of the manifest.
def manifestContent = file(manifestPath).getText()
// Changes the version code in the stored text.
manifestContent = manifestContent.replace('android:versionCode="1"',
String.format('android:versionCode="%s"', generatedCode))
// Overwrites the manifest with the new text.
file(manifestPath).write(manifestContent)
}
}
}
I may apply it in wrong way because no resources that cover this topic.
I also try this answer .. Error:Manifest Tasks does not support the manifestOutputFile property any more, please use the manifestOutputDirectory instead. (Android Studio 3.0)
for all my trials the error still exist ..
When trying to enable multi-dexing for an application over 65K, following the guidelines specified by the android developer page here
While in my application build.gradle I specify:
android.applicationVariants.all{
variant -> variant.outputs.each {
output ->
output.processResources.manifestFile = file('AndroidManifest.xml')
output.processManifest.enabled=false
}
}
Upon running build I receive this error,
Error: A problem was found with the configuration of task ':myapp:collectDebugMultiDexComponents'.
File 'C:\Android Projects\myappapp\build\intermediates\manifests\full\debug\AndroidManifest.xml' specified for property 'manifest' does not exist.
Open to any suggestions or advice to properly direct multi dex task to actual AndroidManifest.xml path. When removing the library that causes the application to cross the 64k limit and removing multidexing the application builds fine.
Is it possible to specify the filename of the generated *.apk through gradle? So that I automatically could get MyApp-1.0.0.apk instead of the default app-release.apk.
You can do this by adding the following line to your build.gradle file inside the android{...} part:
android.applicationVariants.all { variant ->
variant.outputFile = file("$project.buildDir/${defaultConfig.versionName}-${defaultConfig.versionCode}.apk")
}
Notes:
Everything inside the file(...) is arbitrary, of course
This code will output the *.apk to your project/module/build directory, no matter what path you've specified when Building the Signed APK.
The output-file will take the Name and Version-Code from your build.gradle file.
Android Studio may complain that it "cannot resolve symbol applicationVariants/defaultConfig" - ignore it. ;)
Got it working! Used this answer
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
}
}
}
1- Why is the following:
android.buildVariants.each { variant ->
... my code
}
giving me the following error?
Could not find property 'buildVariants' on com.android.build.gradle.AppExtension_Decorated#1bf6bde6.
2- Why is the following silently not executing "... my code"?
android.applicationVariants.each { variant ->
... my code
}
The Android Build System now uses "applicationVariants" instead of "buildVariants". However, "android.applicationVariants.each" will also not work, see below.
Since the Android Build System 0.5.5 release you must use "android.applicationVariants.all" instead of "android.applicationVariants.each", as applicationVariants will remain empty with a call to each.
I am using the new gradle android buildsystem.
The project consists of two android library projects and one main project.
Using the ant build, the manifest merger must be enable in project.properties. But when using the gradle build system the manifest merger is enabled by default. How can i disable the manifest merger?
Edit: this is actually possible though indirectly, starting with 0.3
What you need to do is disable the processManifest task so that it doesn't run and tell the processResources where the manifest to use is:
android.applicationVariants.all { variant ->
variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
variant.processManifest.enabled=false
}
Note that if you are customizing the app package name through the DSL, you should keep the default manifest untouched in the default location to provide a consistent package name for the R classes, and then have your manually merged manifests somewhere else and point each variant processResources task to them.
This may help.
android.applicationVariants.all{ variant ->
variant.outputs.each { output ->
output.processResources.manifestFile = file('AndroidManifest.xml')
output.processManifest.enabled=false
}
}
For the 0.6.+ plugin you also have to change from buildVariants to applicationVariants:
android.applicationVariants.all { variant ->
variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
variant.processManifest.enabled=false
}
It doesn't look like these solutions work for the 1.0 plugin:
Could not find property 'processResources' on
com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated#774f1d0b.
Anyone have an update? Our issue is a stray activity showing up in the final apk from recyclerview-v7:21.0.3:
<activity
android:label="RecyclerViewTestActivity"
android:name="android.support.v7.widget.TestActivity"/>
Update: It looks like manifest merging can be configured (see http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger ). In this specific case, the TestActivity coming from the recyclerview-v7 library can be removed with:
<activity
android:name="android.support.v7.widget.TestActivity"
android:label="RecyclerViewTestActivity"
tools:node="remove"/>
Thanks Filip.
For the 0.5.+ plugin you have to change from each to all like this:
android.buildVariants.all { variant ->
variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
variant.processManifest.enabled=false
}