简体   繁体   中英

react-native run-android error "Task :app:javaPreCompileDebug FAILED"

EDIT: This issue was solved by forcing the gradle not to jetify my native library. This is done by adding in gradle.properties

android.jetifier.blacklist = your-causing-issues-library

For more details you can read the official docs or this post



I need to use some native code in a react native project. The native code is provided in a .jar file by the hardware manufacturer. In a clean project (react-native init), with this .jar file inside /android/app/libs folder, this error shows as soon as I try to run "react native run-android".

==============

Error is as follow:

Task :app:javaPreCompileDebug FAILED 6 actionable tasks: 6 executed

FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':app:javaPreCompileDebug'. Could not resolve all files for configuration ':app:debugCompileClasspath'. Failed to transform file 'iMagPayV5.1.4.jar' to match attributes {artifactType=android-classes, org.gradle.usage=java-runtime-jars} Execution failed for JetifyTransform: /home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar. Failed to transform '/home/buonapasta/Desktop/React-Native/samples/project/android/app/libs/iMagPayV5.1.4.jar' using Jetifier. Reason: 10. (Run with --stacktrace for more details.)

==============

Help is appreciated in advance!! (Sorry if some information is incomplete).

React Native version 0.60.4 running on Ubuntu 18.04. I've tried to include some other .jar files in a clean project without inconvenience, but as soon as I include this particular .jar everything blows. Also, this library is working on an Android Studio project. The .jar can be found on https://github.com/GPaoloni/imagpay-framework

android/app/build.gradle looks like this:

...

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

android/build.gradle:

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")

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

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
    }
}

I just want being able to include the .jar library (to be used by a native activity).

==============

Update:

I've tried doing like sugested:

npm install --save-dev jetifier
npx jetify

But the error still the same.

Reading the npm page of jetifier, in the "Usage for jar/zip/aar files" section:

npm install jetifier
npx jetifier-standalone <your arguments here>

Runing this gives me the following error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
    at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
    at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:39)
    at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:443)
    at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:49)
    at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:425)
    at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
    at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:421)
    at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:247)
    at com.android.tools.build.jetifier.processor.Processor.transform$default(Processor.kt:234)
    at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:157)
    at com.android.tools.build.jetifier.standalone.Main$Companion.main(Main.kt:109)
    at com.android.tools.build.jetifier.standalone.Main.main(Main.kt)

Try executing these line by line.
1. yarn
2. yarn start

On a new terminal tab
1. react-native run-android

Check whether 'jetifier' running output is displayed on the terminal.

Something similar to this.

"Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag."

If not run these before executing 'react-native run-android'
1. npm install --save-dev jetifier
2. npx jetify

I am using VS Code and installed prettier and format on-save. For some reason, when I saved page, he formatted wrong and I had this error, when discarded changes, it started working well, u can try this, as prevention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM