10

I've got a rather complicated project some of which is older code from the past year or so which in React Native time is forever. The regular debug build is working fine but the release build has errors. I've cobbled together answers from other places to make it as far as I have but I don't know how to get past this last bit.

I keep getting a bundling error where aapt will fail because it doesn't bundle the resources properly.

Example of error code:

> Task :app:bundleReleaseJsAndAssets 
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (9ms)
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (6ms)
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/android/app/build/intermediates/assets/release/index.android.bundle
bundle: Done writing bundle output

error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.

/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.

/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.

error: failed linking references.

FAILURE: Build failed with an exception.

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

2 Answers 2

27

Building upon GenericJam's answer, you can do this programatically to all sub libraries by doing something like this in your project build.gradle file:

subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}
0
20

The way to solve this that worked for me is to dive into the node_modules code for the supporting libraries that are triggering the error.

You will need to go into node_modules/project-name/android/build.gradle and change this

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    ...
}

to whatever the sdk version is in your /android/app/build.gradle is. For example:

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"
    ...
}

Hopefully this will be fixed in React Native so this workaround isn't necessary.

Edit: I suspect Petter's solution is the better one although I haven't tried it myself. Probably try that one first and if it doesn't work, try this next.

4
  • THANK YOU! The only thing that ended up working for me. Also important to note: this only worked once I downgraded gradle back to pre-3.0, which I must have upgraded via the IDE on accident. Aug 14, 2018 at 2:19
  • You deserve 1000k up votes for this solution. Thank you!
    – haotang
    Oct 9, 2018 at 1:21
  • @GenericJam Hello, what's do u mean of Project-Name inside Node_modules? I don't have anything inside them ?
    – DevAS
    Jan 22, 2019 at 21:48
  • @Gha Example: your_app/node_modules/react-native-camera/android/build.gradle. Not all dependencies have the android directory. If it doesn't have that this probably isn't the problem for you. Maybe try Petter's solution.
    – GenericJam
    Jan 23, 2019 at 22:45

Your Answer

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

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