英文:
Activity class {rcm.samapp/com.comp.android.ui....} does not exist
问题
I am trying to integrate react native and native android app.
applicationId in apps build.gradle is rcm.samapp
package in manifest tag is com.comp.android.
Line 1 in SplashActivity.kt is package com.comp.android.ui
activity is Manifest looks like:
<activity
android:name=".ui.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
After following the official RN doc, when I try to run it through react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity command, it throws this error:
Starting: Intent { cmp=rcm.samapp/com.comp.android.ui.SplashActivity }
Error type 3
Error: Activity class {rcm.samapp/com.comp.android.ui.SplashActivity} does not exist.
What can be the reason and fix?
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply from: 'appcenter.gradle'
apply from: 'version.gradle'
apply plugin: 'jacoco'
apply plugin: 'org.owasp.dependencycheck'
apply from: 'checkstyle.gradle'
project.afterEvaluate {
preBuild.dependsOn 'checkstyle'
}
repositories {
flatDir {
dirs 'libs'
}
}
project.ext.react = [
entryFile: "index.js",
enableHermes: false,  // clean and rebuild if changing
]
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
dependencyCheck {
scanConfigurations += 'releaseCompileClasspath'
}
android {
compileSdkVersion 29
def versionNameValue = System.getProperty("suppliedVersionName", "1.0.0")
def versionCodeValue = System.getProperty("suppliedVersionCode", calculatedVersionCode)
packagingOptions {
    pickFirst '**/*.so'
}
dexOptions {
    javaMaxHeapSize "4g"
}
lintOptions {
    abortOnError false
    disable 'MissingTranslation'
}
defaultConfig {
    applicationId "rcm.samapp"
    minSdkVersion 21
    targetSdkVersion 28
    versionName versionNameValue
    versionCode (versionCodeValue.toInteger() + 10000)
    vectorDrawables.useSupportLibrary = true
    multiDexEnabled true
    def backend = backend()
    resValue 'bool', 'debugMenu', 'false'
}
dataBinding {
    enabled = true
}
kotlinOptions {
    jvmTarget = '1.8'
}
compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
    sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
    exclude 'lib/mips64/**'
    exclude 'lib/mips/**'
    exclude 'lib/armeabi/**'
}
buildTypes {
    android.applicationVariants.all { variant ->
        variant.getAssembleProvider().configure() {
            it.doFirst {
       ...
            }
            it.doLast {
                ...
            }
        }
    }
    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable true
        testCoverageEnabled true
        applicationIdSuffix ".debug.dev"
        versionNameSuffix ".debug.$currentBranchName"
        signingConfig signingConfigs.debug
        buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
    }
    development.initWith(release)
    development {
        debuggable true
        applicationIdSuffix '.debug'
        versionNameSuffix ".development.$currentBranchName"
        signingConfig signingConfigs.debug
        buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
        resValues.remove 'debugMenu';
        resValue 'bool', 'debugMenu', 'true';
    }
}
sourceSets {
    debug.java.srcDirs        += 'src/environments_debug/java';
    development.java.srcDirs  += 'src/environments_debug/java';
    release.java.srcDirs      += 'src/environments_release/java';
    debug {
        jniLibs.srcDir 'src/jniLibsDebug';
    }
    development {
        jniLibs.srcDir 'src/jniLibsRelease';
    }
    release {
        jniLibs.srcDir 'src/jniLibsRelease';
    }
}
testOptions {
    animationsDisabled = true;
    animationsDisabled true;
    unitTests {
        includeAndroidResources = true;
    }
}
}
def backend() {
return project.getProperties().get("backend");
}
ext {
lifeCycle = '2.2.0';
dagger = '2.27';
retrofit = '2.4.0';
room = '2.2.5';
glide = '4.11.0';
espresso = '3.2.0';
databinding = '4.0.0';
appCenterSdkVersion = '3.2.1';
}
dependencyCheck {
// Only check for vulnerabilities in the dependencies of the production release
scanConfigurations += 'releaseCompileClasspath';
}
jacoco {
toolVersion = "$jacocoVersion";
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true;
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
}
dependencies {
releaseImplementation files('libs/libidpmobile.jar');
developmentImplementation files('libs/libidpmobile.jar');
debugImplementation files('libs/libidpmobile-debug.jar');
if (enableHermes) {
    def hermesPath = "../../node_modules/hermesvm/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar");
    releaseImplementation files(hermesPath + "hermes-release.aar");
} else {
    implementation jscFlavor;
}
implementation 'com.android.support:appcompat-v7:27.1.1';
...implementations
testImplementation 'junit:junit:4.13';
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesAppBuildGradle(project);
// THIS NEEDS TO BE IN THE BOTTOM
apply plugin: 'com.google.gms.google-services';
英文:
I am trying to integrate react native and native android app.
applicationId in apps build.gradle is rcm.samapp
package in manifest tag is com.comp.android.
Line 1 in SplashActivity.kt is package com.comp.android.ui
activity is Manifest looks like:
 <activity
      android:name=".ui.SplashActivity"
      android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
 </activity>
After following the official RN doc, when I try to run it through react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity command, it throws this error:
Starting: Intent { cmp=rcm.samapp/com.comp.android.ui.SplashActivity }
Error type 3
Error: Activity class {rcm.samapp/com.comp.android.ui.SplashActivity} does not exist.
What can be the reason and fix?
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply from: 'appcenter.gradle'
apply from: 'version.gradle'
apply plugin: 'jacoco'
apply plugin: 'org.owasp.dependencycheck'
apply from: 'checkstyle.gradle'
project.afterEvaluate {
    preBuild.dependsOn 'checkstyle'
}
repositories {
    flatDir {
        dirs 'libs'
    }
}
project.ext.react = [
        entryFile: "index.js",
        enableHermes: false,  // clean and rebuild if changing
]
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
dependencyCheck {
    scanConfigurations += 'releaseCompileClasspath'
}
android {
    compileSdkVersion 29
    def versionNameValue = System.getProperty("suppliedVersionName", "1.0.0")
    def versionCodeValue = System.getProperty("suppliedVersionCode", calculatedVersionCode)
    packagingOptions {
        pickFirst '**/*.so'
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    lintOptions {
        abortOnError false
        disable 'MissingTranslation'
    }
    defaultConfig {
        applicationId "rcm.samapp"
        minSdkVersion 21
        targetSdkVersion 28
        versionName versionNameValue
        versionCode (versionCodeValue.toInteger() + 10000)
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        def backend = backend()
        resValue 'bool', 'debugMenu', 'false'
    }
    dataBinding {
        enabled = true
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        exclude 'lib/mips64/**'
        exclude 'lib/mips/**'
        exclude 'lib/armeabi/**'
    }
    buildTypes {
        android.applicationVariants.all { variant ->
            variant.getAssembleProvider().configure() {
                it.doFirst {
                   
           ...
                }
                it.doLast {
                    ...
                }
            }
        }
 
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
            testCoverageEnabled true
            applicationIdSuffix ".debug.dev"
            versionNameSuffix ".debug.$currentBranchName"
            signingConfig signingConfigs.debug
            buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
        }
        development.initWith(release)
        development {
            debuggable true
            applicationIdSuffix '.debug'
            versionNameSuffix ".development.$currentBranchName"
            signingConfig signingConfigs.debug
            buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
            resValues.remove 'debugMenu'
            resValue 'bool', 'debugMenu', 'true'
        }
    }
    sourceSets {
        debug.java.srcDirs        += 'src/environments_debug/java'
        development.java.srcDirs  += 'src/environments_debug/java'
     
        release.java.srcDirs      += 'src/environments_release/java'
        debug {
            jniLibs.srcDir 'src/jniLibsDebug'
        }
        development {
            jniLibs.srcDir 'src/jniLibsRelease'
        }
        release {
            jniLibs.srcDir 'src/jniLibsRelease'
        }
    }
    testOptions {
        animationsDisabled = true
        animationsDisabled true
        unitTests {
            includeAndroidResources = true
        }
    }
}
def backend() {
    return project.getProperties().get("backend")
}
ext {
      lifeCycle = '2.2.0'
    dagger = '2.27'
    retrofit = '2.4.0'
    room = '2.2.5'
    glide = '4.11.0'
    espresso = '3.2.0'
    databinding = '4.0.0'
    appCenterSdkVersion = '3.2.1'
}
dependencyCheck {
    // Only check for vulnerabilities in the dependencies of the production release
    scanConfigurations += 'releaseCompileClasspath'
}
jacoco {
    toolVersion = "$jacocoVersion"
}
tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
}
dependencies {
    releaseImplementation files('libs/libidpmobile.jar')
    developmentImplementation files('libs/libidpmobile.jar')
    debugImplementation files('libs/libidpmobile-debug.jar')
    if (enableHermes) {
        def hermesPath = "../../node_modules/hermesvm/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
    implementation 'com.android.support:appcompat-v7:27.1.1'
	...implementations
 
    testImplementation 'junit:junit:4.13'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
// THIS NEEDS TO BE IN THE BOTTOM
apply plugin: 'com.google.gms.google-services'
答案1
得分: 0
你有一些带有applicationIdSuffix的自定义构建变体,它们会改变包名。你也应该在run-android命令中设置它们。
据我所理解,你需要运行development变体。所以设置为--variant development。development变体中的applicationIdSuffix是.debug。将其指定为--appIdSuffix debug。
针对development变体的完整命令如下:react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity --variant development --appIdSuffix debug。
英文:
You have some custom build variants with applicationIdSuffix which are changing package name. You should set them as well in your run-android command.
As far I understood, you need to run development variant. So set --variant development. applicationIdSuffix in development variant is .debug. Specify it as --appIdSuffix debug.
The full command for development variant would be: react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity --variant development --appIdSuffix debug
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论