React Native Navigation看起来是在本地反应场景之间导航的最佳选择,但我无法在我的android项目中安装它。我确信我按照文档所说的所有内容进行了操作,{{3 }
这是完整版本(Stackoverflow不允许大块代码,所以我只是确定了什么看起来不对):
C:\wixNav>react-native run-android
Scanning folders for symlinks in C:\wixNav\node_modules (25ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
Observed package id 'system-images;android-26;android-wear;x86' in inconsistent location 'C:\Users\felip\AppData\Local\Android\Sdk\system-images\android-26\android-wear-cn\x86' (Expected 'C:\Users\felip\AppData\Local\Android\Sdk\system-images\android-26\android-wear\x86')
Observed package id 'system-images;android-26;android-wear;x86' in inconsistent location 'C:\Users\felip\AppData\Local\Android\Sdk\system-images\android-26\android-wear-cn\x86' (Expected 'C:\Users\felip\AppData\Local\Android\Sdk\system-images\android-26\android-wear\x86')
downloadRobolectricDependencies C:\wixNav\android\build/robolectric-dependencies
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:react-native-navigation:preBuild UP-TO-DATE
:react-native-navigation:preReleaseBuild UP-TO-DATE
:react-native-navigation:checkReleaseManifest
:react-native-navigation:preDebugAndroidTestBuild UP-TO-DATE
:react-native-navigation:preDebugBuild UP-TO-DATE
:react-native-navigation:preDebugUnitTestBuild UP-TO-DATE
:react-native-navigation:preReleaseUnitTestBuild UP-TO-DATE
:react-native-navigation:prepareComAndroidSupportAnimatedVectorDrawable2531Library
:react-native-navigation:prepareComAndroidSupportAppcompatV72531Library
:react-native-navigation:prepareComAndroidSupportDesign2531Library
:react-native-navigation:prepareComAndroidSupportRecyclerviewV72531Library
:react-native-navigation:prepareComAndroidSupportSupportCompat2531Library
:react-native-navigation:prepareComAndroidSupportSupportCoreUi2531Library
:react-native-navigation:prepareComAndroidSupportSupportCoreUtils2531Library
:react-native-navigation:prepareComAndroidSupportSupportFragment2531Library
:react-native-navigation:prepareComAndroidSupportSupportMediaCompat2531Library
:react-native-navigation:prepareComAndroidSupportSupportV42531Library
:react-native-navigation:prepareComAndroidSupportSupportVectorDrawable2531Library
:react-native-navigation:prepareComAndroidSupportTransition2531Library
:react-native-navigation:prepareComAurelhubertAhbottomnavigation206Library
:react-native-navigation:prepareComBalysvMaterialmenuMaterialMenu154Library
:react-native-navigation:prepareComBalysvMaterialmenuMaterialMenuToolbar154Library
:react-native-navigation:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library
:react-native-navigation:prepareComFacebookFrescoDrawee130Library
:react-native-navigation:prepareComFacebookFrescoFbcore130Library
:react-native-navigation:prepareComFacebookFrescoFresco130Library
:react-native-navigation:prepareComFacebookFrescoImagepipeline130Library
:react-native-navigation:prepareComFacebookFrescoImagepipelineBase130Library
:react-native-navigation:prepareComFacebookFrescoImagepipelineOkhttp3130Library
:react-native-navigation:prepareComFacebookReactReactNative0533Library
:react-native-navigation:prepareComFacebookSoloaderSoloader010Library
:react-native-navigation:prepareOrgWebkitAndroidJscR174650Library
:react-native-navigation:prepareReleaseDependencies
:react-native-navigation:compileReleaseAidl
:react-native-navigation:compileReleaseNdk UP-TO-DATE
:react-native-navigation:compileLint
:react-native-navigation:copyReleaseLint UP-TO-DATE
:react-native-navigation:compileReleaseRenderscript
:react-native-navigation:generateReleaseBuildConfig
:react-native-navigation:generateReleaseResValues
:react-native-navigation:generateReleaseResources
:react-native-navigation:mergeReleaseResources
:react-native-navigation:processReleaseManifest
:react-native-navigation:processReleaseResources
:react-native-navigation:generateReleaseSources
:react-native-navigation:incrementalReleaseJavaCompilationSafeguard
:react-native-navigation:compileReleaseJavaWithJavac
:react-native-navigation:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:react-native-navigation:extractReleaseAnnotations
:react-native-navigation:mergeReleaseShaders
:react-native-navigation:compileReleaseShaders
:react-native-navigation:generateReleaseAssets
:react-native-navigation:mergeReleaseAssets
:react-native-navigation:mergeReleaseProguardFiles UP-TO-DATE
:react-native-navigation:packageReleaseRenderscript UP-TO-DATE
:react-native-navigation:packageReleaseResources
:react-native-navigation:processReleaseJavaRes UP-TO-DATE
:react-native-navigation:transformResourcesWithMergeJavaResForRelease
:react-native-navigation:transformClassesAndResourcesWithSyncLibJarsForRelease
:react-native-navigation:mergeReleaseJniLibFolders
:react-native-navigation:transformNative_libsWithMergeJniLibsForRelease
:react-native-navigation:transformNative_libsWithSyncJniLibsForRelease
:react-native-navigation:bundleRelease
:app:prepareComAndroidSupportAnimatedVectorDrawable2531Library
:app:prepareComAndroidSupportAppcompatV72531Library
:app:prepareComAndroidSupportDesign2531Library
:app:prepareComAndroidSupportRecyclerviewV72531Library
:app:prepareComAndroidSupportSupportCompat2531Library
:app:prepareComAndroidSupportSupportCoreUi2531Library
:app:prepareComAndroidSupportSupportCoreUtils2531Library
:app:prepareComAndroidSupportSupportFragment2531Library
:app:prepareComAndroidSupportSupportMediaCompat2531Library
:app:prepareComAndroidSupportSupportV42531Library
:app:prepareComAndroidSupportSupportVectorDrawable2531Library
:app:prepareComAndroidSupportTransition2531Library
:app:prepareComAurelhubertAhbottomnavigation206Library
:app:prepareComBalysvMaterialmenuMaterialMenu154Library
:app:prepareComBalysvMaterialmenuMaterialMenuToolbar154Library
:app:prepareComFacebookFbuiTextlayoutbuilderTextlayoutbuilder100Library
:app:prepareComFacebookFrescoDrawee130Library
:app:prepareComFacebookFrescoFbcore130Library
:app:prepareComFacebookFrescoFresco130Library
:app:prepareComFacebookFrescoImagepipeline130Library
:app:prepareComFacebookFrescoImagepipelineBase130Library
:app:prepareComFacebookFrescoImagepipelineOkhttp3130Library
:app:prepareComFacebookReactReactNative0533Library
:app:prepareComFacebookSoloaderSoloader010Library
:app:prepareOrgWebkitAndroidJscR174650Library
:app:prepareWixNavReactNativeNavigationUnspecifiedLibrary
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\wixNav\android\app\src\main\java\com\wixnav\MainApplication.java:71: error: class, interface, or enum expected
public String getJSMainModuleName() {
^
C:\wixNav\android\app\src\main\java\com\wixnav\MainApplication.java:73: error: class, interface, or enum expected
}
^
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
Total time: 36.407 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
然后我执行了npm install并显示了这个:
:app:prepareComFacebookSoloaderSoloader010Library UP-TO-DATE
:app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
:app:prepareWixNavReactNativeNavigationUnspecifiedLibrary FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:prepareWixNavReactNativeNavigationUnspecifiedLibrary'.
> Could not expand ZIP 'C:\wixNav\node_modules\react-native-navigation\android\app\build\outputs\aar\react-native-navigation-release.aar'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.285 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
我的MainAplication.java:
package com.wixnav;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.reactnativenavigation.NavigationReactPackage;
import com.reactnativenavigation.NavigationReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
import com.reactnativenavigation.NavigationApplication;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new NavigationReactPackage(),
new NavigationReactPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
public class MainApplication extends NavigationApplication {
@Override
public boolean isDebug() {
// Make sure you are using BuildConfig from your own application
return BuildConfig.DEBUG;
}
protected List<ReactPackage> getPackages() {
// Add additional packages you require here
// No need to add RnnPackage and MainReactPackage
return Arrays.<ReactPackage>asList(
// eg. new VectorIconsPackage()
);
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
@Override
public String getJSMainModuleName() {
return "index";
}
}
答案 0 :(得分:0)
public String getJSMainModuleName() {
^
MainApplication.java:73: error: class, interface, or enum expected
听起来你试图在顶层定义该方法。你不能用Java做到这一点。你的所有方法都必须在一个类中。
答案 1 :(得分:0)
解决方案是:当文档说修改某个文件时,转到github上的示例并复制那里的内容,只是不要在需要项目名称的行中执行
答案 2 :(得分:0)
您两次声明了MainApplication。粘贴
后 public class MainApplication extends NavigationApplication { ...
从文档中。您应该删除MainApplication的原始定义,即下面的代码
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new NavigationReactPackage(),
new NavigationReactPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}