SoFunction
Updated on 2025-04-11

Android Gradle Plug 4.1.0 failed to obtain manifest location after upgrading gradle

Problem background

During the project compilation process, the gradle plug-in similar to Android Gradle Plugin is used for compilation. When the apk is finally packaged, the manifest file will be dynamically modified.

Recently, I found that online users have responded that after upgrading to the following development environment, there is no configuration in the manifest file after packaging the apk.

Android Gradle Plugin:4.1.0
Gradle:6.5
Android Studio:4.1

Confirm the investigation direction

First of all, we need to confirm clearly which of the above three issues is caused by the upgrade.

The following conclusions are verified by the local environmental upgrade process:

Android Gradle Plugin:4.1.0 Mandatory Android Studio:4.1 + Gradle:6.5. However, the packaging process is normal under the following environments:

Android Gradle Plugin:4.0.2
Gradle:6.5
Android Studio:4.1

Android Gradle Plugin:4.0.2 is the previous version of 4.1. It can be confirmed that it is an incompatibility issue caused by the upgrade of Android Gradle Plugin:4.1.0.

After clarifying the direction of the investigation, we can make targeted next.

Investigation and analysis

Our gradle plug-in is processed through the following code:

new File(().().getAsFile(), "")

In fact, it is not that simple, but this sentence is the most critical. After adding some key print statements to the gradle plugin, I got the following error prompt during the compilation process:

Could not get unknown property 'manifestOutputDirectory' for task ':app:processDebugManifest' of type

I asked Baidu and found that there was no relevant record. After all, it was only two months since Android Gradle Plugin: 4.1.0 was officially released, so I had to be self-sufficient.

It is obvious that the attributes that read the location of the manifest file have failed, so the most direct way is to look at the source code. Just find the jar package for Android Gradle Plugin:4.1.0.

It's Baidu again, but it's a pity that there is no download address.

I searched on JCenter, but the JCenter repository was only updated to the version.

That's right. It seems that since Android Studio 3.0, Google has transferred Android Gradle Plugin to the Google() repository. Then I can only search for it in the Google() repository. I don't know the specific address for a while. I didn't pay attention to the studio's compilation log output during the previous compilation process. Of course, if it is a brand new engineering environment, if it is compiled, you will definitely find the repository address, but I'm too lazy to do it.

Let’s try your luck in the AS cache path first, but you have to have a direction to try your luck. Don’t forget the classpath configuration of Android Gradle Plugin:

classpath ':gradle:4.1.0'

Sure enough, I found it in the following path:

/Users/jackie/.gradle/caches/modules-2/files-2.1//gradle

There are all kinds of versions that have been loaded. I directly get the jar package of 4.1.0 and look at the source code. I found the following code in :

File mergedManifestOutputFile = new File(((Directory)getMultiApkManifestOutputDirectory().get()).getAsFile(), 
  (new String[] { dirName, 
    "" }));

There is also an abstract method:

public abstract DirectoryProperty getMultiApkManifestOutputDirectory();

It seems that the property has become multiApkManifestOutputDirectory.

If you are not sure, let's take a look at the source code of 4.0.2 and find the following code in :

Copy the codeThe code is as follows:
File manifestOutputFile = new File(((Directory)getManifestOutputDirectory().get()).getAsFile(), (new String[] { (), "" }));

It is obvious that in version 4.0.2, the property that gets the path of the manifest file is indeed manifestOutputDirectory , and the task is essentially an instance of ProcessApplicationManifest, but starting from version 4.1.0, the task becomes an instance of ProcessMultiApkApplicationManifest and the property becomes multiApkMnifestOutputDirectory .

Okay, the rest is to make the version compatible and the task is done.

Copy the codeThe code is as follows:
new File(().().getAsFile(), "")

Summarize

Most gradle-based compilation scripts work the same principle, which is to write custom tasks, do custom special processing before or after a preset task, etc., and more advanced gradle plug-ins are no exception.

Android Gradle Plugin is also just a gradle plug-in officially developed by Google. Each upgrade version will be accompanied by some updates such as "task name change", "task processing content change", "task execution order change", etc. These updates are likely to affect our gradle plug-ins that do special processing based on their "preset task", so most version compatibility issues should be investigated from this direction.

In addition, sometimes Gradle upgrades will also bring some compatibility issues.

This is the article about the problem of solving the problem of failing to obtain the manifest position after Android Gradle Plug 4.1.0 upgrade. For more information about Android Gradle 4.1 upgrade, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!