Darion Badlydone
Darion Badlydone

Reputation: 947

React native build signed APK fails

I have created a new project with react-native with few packages (react-native-camera, react-native-device-info, react-native-elements, react-native-geocoder, react-native-qrcode-scanner, react-native-vector-icons, react-navigation) but I cannot figure out why it doesn't build. I execute this command to generate the APK:

gradlew clean
gradlew assembleRelease

The output is:

If I remove the react-native-device-info package, the error appear with the next installed package that is react-native-camera.

If I set android.enableAapt2=true (the error above it raised with aapt2 disabled) in the grade.properties I got this error:

D:\WorkingCopy\Apps\CpVehicle\src\android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigation_src_views_assets_backicon.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.

My build.gradle file is this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "$rootDir/../node_modules/react-native/android" }
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.google.com' }
        mavenCentral()
        google()
    }
}


subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion '27.1.1'
            }
        }
    }
}

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

When the project was at the beginnig, I built the APK without errors.

If I try to build it with Android Studio, It works fine but opening the app from the device it crash before appear. In the Play Store Console I got this error:

FATAL EXCEPTION: Thread-3
Process: com.cpvehicle, PID: 8053
java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
    at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)

Thanks.

Upvotes: 1

Views: 1859

Answers (1)

Darion Badlydone
Darion Badlydone

Reputation: 947

I found out this solution or better a workaround:

  1. disable aapt2 on gradle.properties

    android.enableAapt2=false

  2. inside subprojects of build.gradle insert this:

    afterEvaluate { project -> if (project.hasProperty("android")) { android { compileSdkVersion 26 } } }

Upvotes: 4

Related Questions