我正在尝试编译我正在处理的react本机模块 . 我认为问题是,而不是 /android/src/main/java...
我有 /android/TeamCode/src/main/java
. 如果是这种情况,我将如何制作它以便在 /android/TeamCode/src
而不是 /android/src
反应原生?但是我不知道这是不是问题,我可能完全错了 .
结构
这是我的项目的样子:
- module
--- index.js
--- package.json
--- android //this is where the below screenshot is from
----- build.gradle
----- TeamCode
------- build.gradle //apply from: '../build.common.gradle'
--- Example //this is the app I am trying to compile
----- index.android.js
----- android
----- package-lock.json
----- other stuff
错误
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/zoe/saas/robotics/ftcnative/Example/android/app/src/main/java/com/example/MainApplication.java:6: error: package com.qualcomm.ftcrobotcontroller does not exist
import com.qualcomm.ftcrobotcontroller.MyPackage;
^
/Users/zoe/saas/robotics/ftcnative/Example/android/app/src/main/java/com/example/MainApplication.java:27: error: cannot find symbol
new MyPackage()
^
symbol: class MyPackage
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
截图
module / example / package.json
{
"name": "Example",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.47.2",
"ftcnative": "file:../"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.0.1",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}
module / index.js
import {NativeModules} from 'react-native';
module.exports = NativeModules.MyModule;
android / build.common.gradle
import java.util.regex.Pattern
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
signingConfigs {
debug {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile rootProject.file('libs/ftc.debug.keystore')
storePassword 'android'
}
}
defaultConfig {
applicationId 'com.qualcomm.ftcrobotcontroller'
minSdkVersion 19
targetSdkVersion 19
/**
* We keep the versionCode and versionName of robot controller applications in sync with
* the master information published in the AndroidManifest.xml file of the FtcRobotController
* module. This helps avoid confusion that might arise from having multiple versions of
* a robot controller app simultaneously installed on a robot controller device.
*
* We accomplish this with the help of a funky little Groovy script that maintains that
* correspondence automatically.
*
* @see <a href="http://developer.android.com/tools/building/configuring-gradle.html">Configure Your Build</a>
* @see <a href="http://developer.android.com/tools/publishing/versioning.html">Versioning Your App</a>
*/
def manifestFile = project(':FtcRobotController').file('src/main/AndroidManifest.xml');
def manifestText = manifestFile.getText()
//
def vCodePattern = Pattern.compile("versionCode=\"(\\d+(\\.\\d+)*)\"")
def matcher = vCodePattern.matcher(manifestText)
matcher.find()
def vCode = Integer.parseInt(matcher.group(1))
//
def vNamePattern = Pattern.compile("versionName=\"(.*)\"")
matcher = vNamePattern.matcher(manifestText);
matcher.find()
def vName = matcher.group(1)
//
versionCode vCode
versionName vName
}
// Advanced user code might just want to use Vuforia directly, so we set up the libs as needed
buildTypes {
release {
// Disable debugging for release versions so it can be uploaded to Google Play.
//debuggable true
ndk {
abiFilters "armeabi-v7a"
}
}
debug {
debuggable true
ndk {
abiFilters "armeabi-v7a"
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir rootProject.file('libs')
}
}
repositories {
flatDir {
dirs rootProject.file('libs')
}
}
apply from: 'build.release.gradle'
android / build.gradle
/**
* Top-level build file for ftc_app project.
*
* It is extraordinarily rare that you will ever need to edit this file.
*/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'TeamCode/src/main/AndroidManifest.xml'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.facebook.react:react-native:+'
}
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"
}
}
}
编辑:
- 当我添加
java.srcDirs += 'android/TeamCode/src/main/java'
时,我得到:
FAILURE:构建因异常而失败 .
- 出了什么问题:任务':ftcnative:compileReleaseJavaWithJavac'的执行失败 .
无法找到源java类:'/ Users/zoe/saas/robotics/ftcnative/android/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/MyModule.java'因为它不属于任何源dirs:'[/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / src / main / java,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / TeamCode / src / main / java,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / src / release / java,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / build / generated / source / r / release,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / build / generated / source / buildConfig / release,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / build / generated / source / aidl / release,/ Users / zoe / saas / robotics / ftcnative / Example / node_modules / ftcnative / android / build / generated / source / rs / release]'
- 当我添加
java.srcDirs += 'android/TeamCode/src/main/java'
时,我仍然收到第一个错误 .
1 回答
我不知道React Native,但在Android中,要做到这一点,你必须改变你的build.gradle . 找到
android
部分,并添加sourceSets
部分,如下所示:请注意,这是 adding 另一个源目录(因为
+=
) .