41

I'm trying to upgrade an application to React Native 0.57.1. I think I've followed all the steps, upgraded all the right files, yet I'm still getting an error that I cannot understand:

:react-native-document-picker:compileReleaseSources UP-TO-DATE
:react-native-document-picker:mergeReleaseResources UP-TO-DATE
:react-native-document-picker:verifyReleaseResourcesC:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.

C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.

C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.

C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/fontStyle not found.

C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/font not found.

C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/fontWeight not found.


error: failed linking references.
:react-native-document-picker:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-document-picker:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

I can't really make sense of these errors, any idea what they mean? How can I find out how to fix this?

I've tried various things, including deleting the .cache directory, changing the gradle version but nothing seems to help. Any idea?

1
  • 1
    I just spent an entire day on this error :-( ugh! Finally found the this post and read the explanation in @hadi-mir 's answer - made sense, implemented it, BAM, good to go. Thanks! Mar 28, 2019 at 22:48

7 Answers 7

61

You need to add following code in your project's android/build.gradle:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion "27.0.2"
            }
        }
    }
}
3
  • 4
    @LukeWilliams It's due a grade dependency mismatch. You're fixing the mismatch with that code. The compileSdkVersion and buildToolsVersion should match what you have in your android/build.gradle Mar 15, 2019 at 22:34
  • 1
    Don't make the same mistake as me and add to your android/app/build.gradle. -20minutes. Apr 19, 2019 at 18:42
  • 2
    This same config might not work for everyone. You should change the value of compiledSdkVersion & buildToolsVersion according to your project's value. For me, it was 28 and 28.0.3 respectively.
    – Shihab
    Oct 27, 2019 at 11:10
56

For me, what fixed the issue was prefixing with app

./gradlew app:assembleRelease
1
  • 3
    though the build works but app later breaks when installed
    – Irfan wani
    Nov 10, 2022 at 12:11
12

Reason for the error:

You have installed react-native-document-picker as a dependency, And the reason for this error is that the configurations of your android/app/build.gradle and node_modules/react-native-document-picker/android/build.gradle mismatch.

Solution

  1. Navigate to node_modules/react-native-document-picker/android/build.gradle
  2. Edit and keep the compileSdkVersion buildToolsVersion minSdkVersion targetSdkVersion same as you have in android/app/build.gradle
  3. Sync the project again.
  4. Run ./gradlew assembleRelease from the terminal.
7
  • Thanks for the explanation although I'd rather not edit package files directly, but it's good to know why it happens.
    – laurent
    Mar 12, 2019 at 9:46
  • Sure thing, Happy to help
    – Hadi Mir
    Mar 13, 2019 at 8:43
  • So every time you clone the project and do npm install you have to do this? I don't think that's a good solution. Jun 25, 2019 at 14:59
  • 1
    @FrancoisBeaulieu well this issue is caused by the external npm dependency. In this particular example, the "react-native-document-picker". I would make a pull request, or clone the repo and update to my needs if I was in the same situation.
    – Rotarepmi
    Jul 12, 2019 at 11:36
  • @Rotarepmi exactly, forks the project or makes a pull request is a good solution. Jul 15, 2019 at 15:23
0

Had another reason for this issue, I had previously modified minSdkVersion. All you need to do is to remove /node_modules/ folder, /android/build and /android/app/build folders, re npm install and perform ./gradlew assembleRelease again.

0

The command cd android && ./gradlew app:assembleRelease do the magic.

I've found a github link where a command help in almost every type of verifyReleaseResource errors. Ref: https://github.com/luggit/react-native-config/issues/330#issuecomment-494915023

0
0

Reason for the error:

In my case, I had installed react-native-thermal-receipt-printer as a dependency, And the reason for this error is that the configurations of your android/build.gradle and node_modules/react-native-thermal-receipt-printer/android/build.gradle mismatch.

Solution

  1. Navigate to node_modules/react-native-thermal-receipt-printer/android/build.gradle
  2. Edit and keep the compileSdkVersion buildToolsVersion minSdkVersion targetSdkVersion same as you have in android/build.gradle
  3. Save it and change dir cd android.
  4. Run ./gradlew clean
  5. Run ./gradlew assembleRelease
0

If you're getting this error by running something like react-native run-android --deviceId DEVICE_ID_HERE, there's a bug on React-Native where it tries to build the app for a specific device (with --deviceId as an argument) using this command ./gradlew build -X lint instead of this one ./gradlew app:build -X lint.

It fails with this error because most of the React-Native apps are multi-module on the Android side and when you don't specify the app name it should build, Gradle tries to guess which one is the root one, thus guessing wrongly and throwing this error.

In order to fix this issue, you may want to patch this issue with yarn patch or npm patch-package commands, the result is something like the following:

diff --git a/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js b/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js
index 1fb363dc18e5719a592014e11e55e3348ce54a28..046585ede2e07a4716d6e9e2a44c2b0d64255103 100644
--- a/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js
+++ b/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js
@@ -159,7 +159,7 @@ function runOnSpecificDevice(args, gradlew, packageName, adbPath, androidProject
 
   if (devices.length > 0 && deviceId) {
     if (devices.indexOf(deviceId) !== -1) {
-      buildApk(gradlew, androidProject.sourceDir);
+      buildApk(gradlew, args.appFolder || androidProject.appName, androidProject.sourceDir);
       installAndLaunchOnDevice(args, deviceId, packageName, adbPath, androidProject);
     } else {
       _cliTools().logger.error(`Could not find device with the id: "${deviceId}". Please choose one of the following:`, ...devices);
@@ -169,10 +169,10 @@ function runOnSpecificDevice(args, gradlew, packageName, adbPath, androidProject
   }
 }
 
-function buildApk(gradlew, sourceDir) {
+function buildApk(gradlew, appName, sourceDir) {
   try {
     // using '-x lint' in order to ignore linting errors while building the apk
-    const gradleArgs = ['build', '-x', 'lint'];
+    const gradleArgs = [`${appName}:build`, '-x', 'lint'];
 
     _cliTools().logger.info('Building the app...');
 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.