Error: Gradle assembleRelease fails to release multiple packages.

Error :(the following is one of them, all of which are in this category)

> Task :ocr_lib:verifyReleaseResources FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':ocr_lib:verifyReleaseResources'. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > Android resource linking failed / Users/lopez /. Gradle/caches/transforms - 2 / files - 2.1 / ec609e8cee787e2dff3592c66b08a66a/core - 1.0.0 / res/values/values. The XML: 57: 5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found. / Users/lopez /. Gradle/caches/transforms - 2 / files - 2.1 / ec609e8cee787e2dff3592c66b08a66a/core - 1.0.0 / res/values/values. The XML: 57: 5-88:25: AAPT: error: resource android:attr/ttcIndex not found.Copy the code

Format, is probably like this, just above the ec609e8cee787e2dff3592c66b08a66a string is not fixed

.gradle\caches\transforms-2\files-2.1(32-bit transforms core-1.1.0.zip md5) \core-1.1.0\res\values\values. XML: AAPT: error: resource Android :attr/ XXX not found

##### PS: ocr_lib is a library in the project, known as a module

Scene:

  1. From the Build menu at the top of the AS IDE, click Make/Clean/Build Project
  2. Click gradle Task in the upper right corner of AS and run commands such AS installUat1Debug/Release to compile and install gradle Task successfully
  3. Click gradle’s Sync button to synchronize
  4. Perform packagingA singleChannel/environment packages can be successful, for example./gradlew assembleUat1Release, notice no matter heredebug/releaseAll buID types are successful
  5. An error occurs when executing multiple Release packages (./gradlew assembleRelease), as shown above
  6. For point 5, the./gradlew assembleDebug command is successfully packaged
  7. The above scenario, based on the same Gradle buildTypes configuration, is only configured
signingConfig signingConfigs.config
minifyEnabled false
Copy the code
PS: This configuration is not obfuscated. In fact, it is not obfuscated by default. It is equivalent to not adding this line, but there are still some problems
  1. TargetSdkVersion is 26 globally
  2. The app Module and problem module have different compileSdkVersion, App Module compileSdkVersion 28, problem Module compileSdkVersion 26
  3. Androidx dependencies have been added to each module, such asImplementation 'androidx. Appcompat: appcompat: 1.2.0'

Analysis:

The gradlew assembleRelease command is used to compile an assembleRelease file. –warning-mode all –info –debug –stacktrace –warning — mode all –info –debug –stacktrace This resource was not used in the project, but the build failed because of this, so it is still a compilation problem

Solution:

  • After various attempts (in the above scenarios), you can fix the problem module’s compileSdkVersion by changing it to the same compileSdkVersion as the App Module’s, or larger
  • Make sure the sub-module compileSdkVersion is higher than 28 because AndroidX compileSdkVersion only supports 28. AndroidX only supports compileSdkVersion28, AndroidX only supports compileSdkVersion28, AndroidX only supports Gradle 4.6, AndroidX only supports compileSdkVersion28. The lowest version of the Gradle plugin supported by AndroidX is 3.2
  • The concept of compileSdkVersion: compileSdkVersion tells Gradle which Android SDK version to use to build your app, and any new API you add requires the Android SDK at the corresponding Level. Modifying compileSdkVersion does not change the runtime behavior. When you modify compileSdkVersion, new compile-warnings and compile-errors may occur, but the new compileSdkVersion is not included in APK: it is used purely at compile time
  • * * Realize task: ocr_lib: verifyReleaseResources AAPT calibration problem of resources. ** App Module compileSdkVersion is the lowest compileSdkVersion required by AndroidX, so it will pass correctly. An assembleRelease command is used to compile gradle packages. The first gradle package is the Register Task: verifyReleaseResources.
  • Since the project’s targetSdkVersion is 26, this task checks that the AndroidX library it relies on contains a resource that is only available to API28. Although you may not actually use this resource, since it is only used to validate the resource, If the target API version does not correspond to the API version that the class library relies on, it will still give you an error saying that the corresponding resource cannot be found. This is the root cause of your confusion.
  • Since I haven’t tested this yet, I assume that although packaging and running are fine, an error will be reported when you run and actually use the resource (I’m not sure if the error type is NotFoundException in Resouce). Since targetSdkVersion specifies 26, even though you are running on API28 devices, it should end up using API26 resources (non-code, such as Android :attr is the system default color) because it implements features that API26 represents.
  • Androidx uses a system attr that is not included in the aar package you are relying on. Instead, it writes a reference to the attr resource (API28) in the AAR. API26 does not have the attr, so it fails because it cannot be found. As far as that task is concerned, all APPT does for us is check resources ahead of time to improve the robustness of your application. To sum up, the suggestion is to do wellFully tested and compatibleAfter that, targetSdkVersion should catch up with compileSdkVersion.
  • The root cause of this problem is probably the above mentioned. What? You asked me how to type a single package and multiple debug packages at the same time, but how can I type multiple release packages at the same time? Realize task: Much why can this command module: verifyReleaseResources (this step, I don’t know, who is a great god trouble told me), you’ll understand when you put one process comparison to you (the following logs to play a single debug packages, at the same time, playing more than one debug package is not posted, if still do not understand, Log gradle to gradle

The former process:

172-2-22-8:xxxproject lopez$ ./gradlew assembleUat2Release

> Task :ocr_lib:stripReleaseDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:stripUat2ReleaseDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

BUILD SUCCESSFUL in 2s
47 actionable tasks: 47 up-to-date
Copy the code

The latter process

172-2-22-8:xxxproject lopez$ ./gradlew assembleRelease

> Task :ocr_lib:stripReleaseDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :app:stripProductReleaseDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.

> Task :ocr_lib:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.
Copy the code