Android problem notes - aar merge package report Execution failed for task ':app:mergeDebugNativeLibs

Go straight:

This article mainly solves the problem of citing aar package dependencies in modules and reporting errors, and the problem of merging aar packages into new aar packages

There are many solutions on the Internet, but they are basically cumbersome or need to change the project structure. Today I will provide the simplest implementation.

First of all, in order to reproduce and solve the problem, a new test project was created . The main app references a module named mylibrary. In order to realize certain functions in the module, it needs to rely on the aar package and related so libraries. The directory structure is as follows:

Problem recurrence:

We generally add flatDir to specify the aar package directory according to the app layer integration method, and add dependency references in dependencies, such as:

 It seems that there is no problem with this reference, and it will report when compiling

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find :test:.
     Required by:
         project :app > project :mylibrary

solution:

Option One:

Change aar package integration to jar package integration. Change the aar suffix to zip, decompress the jar package and resource files (if any), copy the jar package and resource files (if any) to the corresponding directory, and integrate them according to the jar package. If there is a resource file called in the aar package through R.id./R.layout., etc., this integration method may report that the resource file cannot be found.

Option II:

To reference the aar package in the module, you need to configure the path in the project build, flatDir { dirs '../mylibrary/libs' } or flatDir { dirs project(':mylibrary').file('libs') }, such as:

It should be noted that if you update the new version of gradle, you need to configure it in settings.gradle, such as:

 The above solution is to solve the problem of relying on the aar package to compile or run the error in the module.

new question:

Although the solution provided above can solve the integration error reporting problem in this project, if you want to package the module into an aar package for use in other projects, you will find that the aar package referenced in the module cannot be entered.

solution:

Option One:

 It is also possible to change the aar package integration to jar package integration mentioned above. It should be noted that if the resource file is called through R.id./R.layout. in the aar package, this integration method may report that the resource file cannot be found, and you need to test it yourself.

Option II:

Use third-party fat-aar. Import method:

① Add in the dependencies of the root directory build

 
 classpath 'com.github.kezong:fat-aar:1.3.6'

Add example like:

 ② Add in the build plugins of the module

 id 'com.kezong.fat-aar'

Add example:

③ Modify the dependency mode to embed, add an example:

 Repackage to get the merged aar package, the complete sample demo has been uploaded, you can click the merged aar package sample demo to download

Guess you like

Origin blog.csdn.net/qq_27489007/article/details/130111946