Could not get unknown property 'manifestOutputDirectory' - android

I'm trying to "make project" with Android Studio, and I'm getting this error:
Execution failed for task ':myApp:processGoogleDebugManifest'.
Could not get unknown property 'manifestOutputDirectory' for task ':myApp:processGoogleDebugManifest' of type com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest.
Any help please?
EDIT: This error occurred after I updated to gradle v6.5 and plugin v4.1.0. If I revert to gradle v6.1.1 and plugin v4.0.0 the error disappears.

I encountered this same issue today, in my case it was caused by an outdated version of Huawei's AG Connect plugin. I was using com.huawei.agconnect:agcp:1.2.1.301, but when I updated it to com.huawei.agconnect:agcp:1.4.1.300 the issue was fixed.
See Latest Huawei's AG Connect plugin here: https://developer.huawei.com/latest/plugin/agconnect ...Just scroll, you'll find it there haha!
But if Huawei's plugin is not the problem you are having, you can debug the issue by running gradle with --stacktrace option to see where the issue originates from. In Android Studio you can add command line options for gradle in Settings/Build, Execution, Deployment/Compiler/Command-line options.

This solved my same problem:
In the project level build.gradle, replace this:
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
with this:
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Reference: https://github.com/Tencent/tinker/issues/1471#issuecomment-710777366

If you're using bugsnag, replace the following line
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:4.+'
with:
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:5.+'
For further detail, see this issue: Fails with AGP 4.1.0-alpha04 and this comment.

I write it here because this solution saved my day :
We can fix this by simply replacing references to
manifestOutputDirectory
by
multiApkManifestOutputDirectory
enter code here
in your gradle tasks
For example :
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
output.processManifest.doLast { task ->
def outputDir = multiApkManifestOutputDirectory.asFile.get()
String manifestMergerpath = "$outputDir/AndroidManifest.xml"
writeManifest(manifestMergerpath, placeholders)
}
}
}

android.applicationVariants.all {
outputs.all {
processManifestProvider.configure {
val multiApkManifestOutputDirectory = (this as ProcessMultiApkApplicationManifest)
.multiApkManifestOutputDirectory // 👈
doLast {
multiApkManifestOutputDirectory.get()
.asFile
.walkTopDown()
.forEach {
}
}
}
}
}

Related

Cannot query the value of property 'namespace' because configuration of project ':app' has not completed yet

I am upgrading gradle from 6.2 to 7.3.3 but I am getting the error on
Cannot query the value of property 'namespace' because configuration of project ':app' has not completed yet.
This error comes when I comment the below code
// javaCompileOptions {
// annotationProcessorOptions {
// includeCompileClasspath true
// }
// }
If I uncomment the code I get below error
No signature of method: build_e2h4qa61bft5s0ue8tk1wwyzn.android() is applicable for argument types: (build_e2h4qa61bft5s0ue8tk1wwyzn$_run_closure5) values: [build_e2h4qa61bft5s0ue8tk1wwyzn$_run_closure5#2c96e5dc]
this method might be removed from gradle 7.3.3 but I could not find the solution for the first error. I tried with --stacktrace, --debug --info but not getting enough info to solve this.
I was also facing the same issue, the bellow method helped me, you can try it too.
1-> Go to your build.gradle(AppName) file
2->edit the kotlin version to the latest plugin version that you have installed in your Android studio.
buildscript {
ext.kotlin_version = '1.7.10' <--------------------------------
}
update your kotlin version
---->ext.kotlin_version = '1.7.10'

How to encrypt passwords in build.gradle with Android 3.3? Getting "Cannot resolve symbol" in IDE

Since update to Android Studio 3.3 we get a weird warning with some legacy code about encrypted gradle parameters.
In build.gradle we have this line:
apply from: "encryption.gradle"
In encryption.gradle we have this content:
afterEvaluate {
android.applicationVariants.all { variant ->
def pwd = "";
variant.productFlavors.each { flavor ->
if (flavor.ext.has("pwd1")) {
pwd = flavor.ext.pwd1
}
}
if (pwd.isEmpty() && variant.buildType.ext.has("pwd2")) {
pwd = variant.buildType.ext.pwd2
}
variant.resValue 'string', 'pwd', encryptPassword(pwd, variant.signingConfig, variant.applicationId)
}
}
def String encryptPassword(String password, signingConfig, String applicationId) {
...
}
In the code we use it like this:
getString(R.string.pwd)
And since the AS update we get the following error:
Cannot resolve symbol 'pwd'
When compiling/building the project everything runs fine because it can find the parameter. But when working in the IDE, all files that try to use R.string.pwd are marked red and show the error message, which is pretty annoying.
Any way to make this go away easily? SuppressWarnings("all") and SuppressLint("all") are not helping.
Is afterEvaluate the right place to do this or would it be better somehow in the defaultConfig section of build.gradle?
Even i was facing similar issues. so i reverted my gradle to 3.2.1 and it works as expected, it might be a technical glitch/issue with gradle 3.3
While i was on gradle 3.3 i tried invalidating cache for android studio, restarted it etc, but nothing solved the issue.

Android Build failure : Could not get unknown property 'assembleDebug' for project

I need to create Jar and copy to lib folder, which is done in following task :
task copyJarToLib(type: Copy, dependsOn: 'createJar') {
from "build/libs/lib1.jar"
from "build/libs/lib2.jar"
into "../App/libs/"
}
I have to execute this after apk generation. So, I am calling following instruction at the end of the module-app build.gradle :
assembleDebug.finalizedBy(copyJarToLib)
Issue is observed after upgrading the gradle plugin to 3.1.0 and gradle to 4.4.
Same implementation is working fine with gradle 2.3.
If you want to execute something at the end of build, you can do it as follows:
gradle.buildFinished {
copy {
from "build/libs/lib1.jar"
from "build/libs/lib2.jar"
into "../App/libs/"
}
}
If you want to execute task before apk is built the you can:
afterEvaluate {
project.tasks.findByName('preDebugBuild').dependsOn(':<module>:copyJarToLib')
}
base on Android Studio 2020.3.1, you can use follow codes
afterEvaluate {
project.tasks.findByName('preDebugBuild').dependsOn(copyJarToLib)
}

Gradle extend assembleRelease

on gradle 2.1.3 I could do:
assembleRelease
{
doFirst()
{
//some code
}
}
But when I updated to gradle 2.2.0 I get an error:
Error:(12, 1) A problem occurred evaluating project ':MyProj'.
> Could not find method assembleRelease() for arguments [build_6dlppzyvvovwra7h55acb4kp$_run_closure1#543a3981] on project ':MyProj' of type org.gradle.api.Project.
Can you please help me with that?
It seems to be a common issue for version update to 2.2.0. You can find some similar questions on SO, for example here. But they all lead to a common workaround - rewrite your task this way:
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease') {
task.doFirst {
//some code
}
}
}
Not sure, but it seems, that assembleRelease is not available at the moment you try to point it in your script since 2.2.0 version.

Could not find property 'uninstallDebug' on project

In my project I want to run my custom task "MyTask" to run before uninstall happens. Code for the same is
uninstallDebug.dependsOn "MyTask"
When I run this, it fails with an error
Could not find property 'uninstallDebug' on project
whereas, I see a gradle task listed in the Gradle window with that name.
What may be going wrong?
project.afterEvaluate { p ->
p.tasks.uninstallDebug.doFirst {
println 'before uninstall'
}
}
gradle.taskGraph.whenReady {
// if your MyTask is in the same project
uninstallDebug.dependsOn "MyTask"
// if it is else where
uninstallDebug.dependsOn project("someProject").project("subProject).tasks["MyTask"]
}
uninstallDebug along with several other tasks, especially those that have flavor or buildType name in their name are created and added to the gradle taskGraph quite late in the configuration step by the android plugin. What that means, as you have discovered is that you may not be able to refer to them by name early in the config step since they do not exist yet.
The way around this as the other answers point out is to wait until the tasks in question are added to the taskgraph. You can use your line uninstallDebug.dependsOn "MyTask" in either gradle.taskgraph.whenRead{} or project.afterEvaluate {}

Categories

Resources