java npm运行android commad给出找不到符号错误

cyvaqqii  于 2023-06-28  发布在  Java
关注(0)|答案(2)|浏览(76)

虽然我能够使用CRNA创建我的应用程序,并使用npm run eject将其弹出,并使用npm run android运行它,但三周后发生了这种情况。在过去的20个小时里,我删除了node,android studio,android sdk,并再次下载了所有这些。仍然发生相同的错误。我完全不明白这些是因为Gradle、Java还是Android而发生的。我有两个问题。

常见问题

1.我该如何解决这个问题?
2.
a)crna myApp-> cd myApp-> npm运行弹出-> npm运行Android|
b)react-native init myApp-> cd myApp-> react-native run-android
第二个工作很好,但我不喜欢世博会。它似乎编译和运行更慢,并与react-native链接创建了很多错误。我想知道在什么情况下我必须使用其中一个相关。我正准备自杀,所以任何帮助都会得到最好的感谢。

:app:compileDebugJavaWithJavac

:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).

\android\app\src\main\java\com\biktim\MainApplication.java:5: error: cannot find symbol
import com.facebook.react.ReactApplication;
                     ^
symbol:   class ReactApplication
location: package com.facebook.react

\android\app\src\main\java\com\biktim\MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
                     ^
symbol:   class ReactNativeHost
location: package com.facebook.react

\android\app\src\main\java\com\biktim\MainApplication.java:14: error: cannot find symbol
public class MainApplication extends Application implements ReactApplication 
{
                                                        ^
symbol: class ReactApplication

\android\app\src\main\java\com\biktim\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
            ^
symbol:   class ReactNativeHost
location: class MainApplication

\android\app\src\main\java\com\biktim\MainApplication.java:36: error: cannot find symbol
public ReactNativeHost getReactNativeHost() {
     ^
symbol:   class ReactNativeHost
location: class MainApplication

\android\app\src\main\java\com\biktim\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
public class MainActivity extends ReactActivity {
   ^
\android\app\src\main\java\com\biktim\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                                                   ^
symbol:   class ReactNativeHost
location: class MainApplication

\android\app\src\main\java\com\biktim\MainApplication.java:35: error: method does not override or implement a method from a supertype
 @Override
  ^
8 errors
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

www.example.com MainApplication.java

package com.biktim;

import android.app.Application;

import com.facebook.react.ReactApplication;
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;

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()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

www.example.com MainActivity.java

package com.biktim;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "biktim";
}

}

android/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"
        }
    }
}

android/app/build. gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile


project.ext.react = [
   entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
* Set this to true to create two separate APKs instead of one:
*   - An APK that only works on ARM devices
*   - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
    applicationId "com.biktim2"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    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 {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat- 
 v7:${rootProject.ext.supportLibVersion}"
implementation "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'
}

package.json

{
  "name": "biktim2",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.5.0",
    "react-native": "0.57.1"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.45.6",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native"
  }
}
8wigbo56

8wigbo561#

检查package.json和android/app/build. gradle中的react-native版本。

zfciruhq

zfciruhq2#

我已经尝试了所有这一切,但这个错误发生了。安装应用程序失败。确保您已经设置了Android开发环境:https://reactnative.dev/docs/environment-setup.错误:命令失败:./gradlew app:installStageDebug-PreactNativeDevServerPort = 8081
失败:构建完成,但有2次失败。

1:任务失败,出现异常。

  • 哪里出错了:执行任务“:app:compileStageDebugJavaWithJavac”失败。

未能解析配置“:app:stageDebugCompileClasspath”的所有文件。转换react-native-0.70.5-0.70.5.jar(com. facebook. react:react-native:0.70.5)以匹配属性{artifactType = android-classes-jar,org. gradle. libraryelements = jar,org. gradle. status = release,org. gradle. usage = java-runtime}失败。>找不到react-native-0.70.5-0.70.5.jar(com. facebook. react:react-native:0.70.5)。在以下位置搜索:file:/home/abs-lt-567/Desktop/TonalProject/unison-appcode/node_modules/react-native/android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-0.70.5.jar

  • 尝试:

使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获得完整的见解。==============================================================================

2:任务失败,出现异常。

  • 哪里出错了:java. lang. StackOverflowError(无错误消息)

相关问题