模块应用依赖性导致"错误:包x不存在"与实验gradle插件

时间:2016-08-02 21:21:54

标签: android gradle react-native android-gradle

我有一个基于Android NDK的项目,它使用实验性gradle插件。我正在尝试将React Native和React Native Navigation(RNN)模块添加到项目

RNN附带的示例项目按预期构建和运行。但是,为了使RNN与我的项目兼容,我必须更新其build.gradle文件以使用实验性gradle插件:https://github.com/adamski/react-native-navigation/commit/0a848f574cedae83bf8961bd1fafe8a42e4257cc

我遇到以下构建错误:

Error:(64, 1) error: package com.reactnativenavigation.activities does not exist

我已经搜索了SO和网络以寻求解决方案。我可以看到该项目并在AS中导航:

Android Studio RNN module

然而,在导航到主Activity java类时,它会显示无法找到依赖关系的红线,即使它提供了将文件导入主项目(?)的选项。

我的settings.gradle

include ':app'
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../../node_modules/react-native-navigation/android/app/')

项目build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.7.0-rc1'
    }
}
allprojects {
    repositories {
        jcenter()
        maven {  // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/../../node_modules/react-native/android" // node_modules is two levels up from the AndroidStudio project folder
        }
    }
}

该应用的build.gradle

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"
        defaultConfig.with {
            applicationId = "com.company.myapp"
            minSdkVersion.apiLevel = 16
            targetSdkVersion.apiLevel = 22
        }
    }
    android.ndk {
        moduleName = "juce_jni"
        toolchain = "clang"
        stl = "c++_static"
        cppFlags.add("-fsigned-char")
        cppFlags.add("-fexceptions")
        cppFlags.add("-frtti")
        cppFlags.add("-std=c++11")
        cppFlags.add("-DJUCE_ENABLE_LIVE_CONSTANT_EDITOR=0")
        cppFlags.add("-DJUCER_ANDROIDSTUDIO_4330F05B=1")
        cppFlags.add("-DJUCE_APP_VERSION=0.4.0")
        cppFlags.add("-DJUCE_APP_VERSION_HEX=0x400")
        cppFlags.add("-I${project.rootDir}/../../Fonts".toString())
        cppFlags.add("-I${project.rootDir}/../../Source".toString())
        cppFlags.add("-I${project.rootDir}/../iOS".toString())
        cppFlags.add("-I${project.rootDir}/../../../../juce_modules/adamski/PitchDetector/modules".toString())
        cppFlags.add("-I${project.rootDir}/../../Source/LookAndFeel".toString())
        cppFlags.add("-I${project.rootDir}/../../Source/Synth".toString())
        cppFlags.add("-I${project.rootDir}/../../Source/UI".toString())
        ldLibs.add("android")
        ldLibs.add("EGL")
        ldLibs.add("GLESv2")
        ldLibs.add("log")
        platformVersion = 15
    }
    android.sources {
        main {
            jni {
                source {
                    exclude "**/JuceModules/"
                }
            }
        }
    }
    android.buildTypes {
        debug {
            ndk.with {
                debuggable = true
                cppFlags.add("-g")
                cppFlags.add("-DDEBUG=1")
                cppFlags.add("-D_DEBUG=1")
                cppFlags.add("-O0")
                cppFlags.add("-I${project.rootDir}/../../JuceLibraryCode".toString())
                cppFlags.add("-I${project.rootDir}/../../../../JUCE/modules".toString())
                cppFlags.add("-I${project.rootDir}/../../../../juce_modules/adamski".toString())
                cppFlags.add("-DJUCE_ANDROID=1")
                cppFlags.add("-DJUCE_ANDROID_API_VERSION=21")
                cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSNAME=com_company_myapp_MyApp")
                cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/company/myapp/MyApp\"")
                cppFlags.add("-DJUCE_ENABLE_LIVE_CONSTANT_EDITOR=0")
            }
        }
        release {
            signingConfig = $("android.signingConfigs.releaseConfig")
            ndk.with {
                cppFlags.add("-DNDEBUG=1")
                cppFlags.add("-O3")
                cppFlags.add("-I${project.rootDir}/../../JuceLibraryCode".toString())
                cppFlags.add("-I${project.rootDir}/../../../../JUCE/modules".toString())
                cppFlags.add("-I${project.rootDir}/../../../../juce_modules/adamski".toString())
                cppFlags.add("-DJUCE_ANDROID=1")
                cppFlags.add("-DJUCE_ANDROID_API_VERSION=21")
                cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSNAME=com_company_myapp_MyApp")
                cppFlags.add("-DJUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/company/myapp/MyApp\"")
                cppFlags.add("-DJUCE_ENABLE_LIVE_CONSTANT_EDITOR=0")
            }
        }
    }
    android.signingConfigs {
        create("releaseConfig") {
            storeFile = new File("/Users/adamelemental/.android/debug.keystore")
            storePassword = "android"
            keyAlias = "androiddebugkey"
            keyPassword = "android"
            storeType = "jks"
        }
    }
    android.productFlavors {
        create("armeabi") {
            ndk.abiFilters.add("armeabi")
        }
        create("armeabi-v7a") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:+'
    compile 'com.facebook.react:react-native:+'

    // The following do not work with the experimental gradle plugin:
    //    debugCompile project(path: ':react-native-navigation', configuration: 'libraryDebug')
    //    releaseCompile project(path: ':react-native-navigation', configuration: 'libraryRelease')

    compile project (':react-native-navigation')
}

1 个答案:

答案 0 :(得分:2)

删除RNN productFlavors的{​​{1}}部分已经过了这个问题。