当前位置: 首页 > 知识库问答 >
问题:

执行任务“:app:CompiledEbugJavaWithJavac”失败。运行React本机项目时

蒋寒
2023-03-14
    null

Build.Gradle:

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

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

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

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

build.gradle/app:

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.emptyprojecttemplate"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86"
    }
}
buildTypes {
    release {
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // For each separate APK per architecture, set a unique version code as described here:
        // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
        def versionCodes = ["armeabi-v7a":1, "x86":2]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  // null for the universal-debug, universal-release variants
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }
    }
}
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

 // 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'
 }

共有1个答案

商昂然
2023-03-14

您的stacktrace以:错误:无法找到符号导入com.facebook.React.reactApplication开始,这似乎表明它无法找到React库导入。

我将在Github上为您提供一个答案,请阅读:

https://github.com/transistorsoft/react-native-background-geolocation/issues/294

如果其他人也遇到了同样的问题:确保正确添加了新的存储库。根据Android文档,每个maven repo都应该在自己的maven{}块中。

这就是为什么

maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
    url 'some new extra repo'
}

打破依赖关系。正确的版本是

maven {
    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
    url "$rootDir/../node_modules/react-native/android"
}
maven {
    url 'some new extra repo'
}

React原生android错误:找不到符号

最后的手段

可能值得创建一个新的测试项目(使用最新版本),比如react-native init anotherproject,看看它是否运行。

 类似资料: