安卓报错,几天前还是好的.react-native run-android后就报错



  • Installing APK 'react-native-vector-icons-debug-androidTest.apk' on 'Redmi 4X - 6.0.1' for react-native-vector-icons:debugAndroidTest
    Installed on 1 device.

    BUILD SUCCESSFUL

    Total time: 35.37 secs
    Running C:\Users\Administrator\AppData\Local\Android\Sdk/platform-tools/adb -s 18d8961d7cf4 reverse tcp:8081 tcp:8081
    Starting the app on 18d8961d7cf4 (C:\Users\Administrator\AppData\Local\Android\Sdk/platform-tools/adb -s 18d8961d7cf4 shell am start -n com.simpleapp/.MainActivity)...
    Starting: Intent { cmp=com.simpleapp/.MainActivity }
    Error type 3
    Error: Activity class {com.simpleapp/com.simpleapp.MainActivity} does not exist.
    上传几张,可能有用的图片
    0_1499785253462_1.png 0_1499785260892_2.png


  • administrators

    Error type 3我记得一般是因为你改过名字



  • @晴明 什么情况下会导致[改名字],我没有手动改过



  • 这其实问题不大,因为编译和安装都已经成功,只是没有能帮你启动而已。

    导致这个问题很可能是因为 applicationId 与 package name 不一致,你需要检查 3 个地方:

    1. android/app/build.gradle 里 android.defaultConfig.applicationId 是不是 com.simpleapp
    2. android/app/src/AndroidManifest.xml 里是不是 package="com.simpleapp"
    3. android/app/main/java/com/simpleapp/MainActivity.java 的路径是否正确


  • 估计是因为你们项目中有多渠道打包的代码
    把 android/app/build.gradle 文件中的代码贴来看看



  • @privatez apply plugin: "com.android.application"

    import com.android.build.OutputFile

    project.ext.vectoricons = [
    iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] // Name of the font files you want to copy
    ]

    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

    /**

    • The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
    • and bundleReleaseJsAndAssets).
    • These basically call react-native bundle with the correct arguments during the Android build
    • cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
    • bundle directly from the development server. Below you can see all the possible configurations
    • and their defaults. If you decide to add a configuration block, make sure to add it before the
    • apply from: "../../node_modules/react-native/react.gradle" line.
    • project.ext.react = [
    • // the name of the generated asset file containing your JS bundle
    • bundleAssetName: "index.android.bundle",
    • // the entry file for bundle generation
    • entryFile: "index.android.js",
    • // whether to bundle JS and assets in debug mode
    • bundleInDebug: false,
    • // whether to bundle JS and assets in release mode
    • bundleInRelease: true,
    • // whether to bundle JS and assets in another build variant (if configured).
    • // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
    • // The configuration property can be in the following formats
    • // 'bundleIn${productFlavor}${buildType}'
    • // 'bundleIn${buildType}'
    • // bundleInFreeDebug: true,
    • // bundleInPaidRelease: true,
    • // bundleInBeta: true,
    • // the root of your project, i.e. where "package.json" lives
    • root: "../../",
    • // where to put the JS bundle asset in debug mode
    • jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
    • // where to put the JS bundle asset in release mode
    • jsBundleDirRelease: "$buildDir/intermediates/assets/release",
    • // where to put drawable resources / React Native assets, e.g. the ones you use via
    • // require('./image.png')), in debug mode
    • resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
    • // where to put drawable resources / React Native assets, e.g. the ones you use via
    • // require('./image.png')), in release mode
    • resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
    • // by default the gradle tasks are skipped if none of the JS files or assets change; this means
    • // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
    • // date; if you have any other folders that you want to ignore for performance reasons (gradle
    • // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
    • // for example, you might want to remove it from here.
    • inputExcludes: ["android/", "ios/"],
    • // override which node gets called and with what additional arguments
    • nodeExecutableAndArgs: ["node"],
    • // supply additional arguments to the packager
    • extraPackagerArgs: []
    • ]
      */

    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 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.simpleapp"
        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 project(':react-native-cookiemanager')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+" // From node_modules
    compile project(':react-native-vector-icons')
    }

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



  • @7c00 1,2都有,就是没明白你说的1的路径是什么,我贴下mainActivity.java的代码 吧:

    package com.simpleapp;

    import com.facebook.react.ReactActivity;
    import com.oblador.vectoricons.VectorIconsPackage;

    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 "SimpleApp";
    }
    

    }



  • 好吧,看起来不是我以为的问题。
    你还可以试试手动删掉手机里的应用,删除 /build 和 app/build,重新 run-android。



  • @MTTTM 说:

    Installing APK 'react-native-vector-icons-debug-androidTest.apk' on 'Redmi 4X - 6.0.1' for react-native-vector-icons:debugAndroidTest

    主要问题应该是你报错第一条日志 如果是正常的话应该是
    Installing APK 'app-debug.apk' on 'Redmi 4X - 6.0.1' for app:debug

    之前我碰到这个问题就是因为我开启了多渠道打包 但是查看过你的 build 文件后发现没有相关代码 QAQ
    不过 你的 build.gradle/dependencies 中有两句 compile project(':react-native-vector-icons')
    我尝试在我本机上复现好像和这个没关系 不过你可以在你那边试试看



  • 你也可以尝试下 @7c00 说的清除一下 gradle 的缓存在 run-android
    在你的主项目下 cd android && ./gradlew clean && cd ..


登录后回复