Activity类{rcm.samapp/com.comp.android.ui….}不存在。

huangapple go评论35阅读模式
英文:

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:

 &lt;activity
      android:name=&quot;.ui.SplashActivity&quot;
      android:screenOrientation=&quot;portrait&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
            &lt;/intent-filter&gt;
 &lt;/activity&gt;

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: &#39;com.android.application&#39;
apply plugin: &#39;kotlin-android&#39;
apply plugin: &#39;kotlin-kapt&#39;
apply plugin: &#39;kotlin-android-extensions&#39;
apply from: &#39;appcenter.gradle&#39;
apply from: &#39;version.gradle&#39;
apply plugin: &#39;jacoco&#39;
apply plugin: &#39;org.owasp.dependencycheck&#39;
apply from: &#39;checkstyle.gradle&#39;

project.afterEvaluate {
    preBuild.dependsOn &#39;checkstyle&#39;
}
repositories {
    flatDir {
        dirs &#39;libs&#39;
    }
}

project.ext.react = [
        entryFile: &quot;index.js&quot;,
        enableHermes: false,  // clean and rebuild if changing
]
def jscFlavor = &#39;org.webkit:android-jsc:+&#39;
def enableHermes = project.ext.react.get(&quot;enableHermes&quot;, false);

dependencyCheck {
    scanConfigurations += &#39;releaseCompileClasspath&#39;
}

android {

    compileSdkVersion 29
    def versionNameValue = System.getProperty(&quot;suppliedVersionName&quot;, &quot;1.0.0&quot;)
    def versionCodeValue = System.getProperty(&quot;suppliedVersionCode&quot;, calculatedVersionCode)

    packagingOptions {
        pickFirst &#39;**/*.so&#39;
    }

    dexOptions {
        javaMaxHeapSize &quot;4g&quot;
    }

    lintOptions {
        abortOnError false
        disable &#39;MissingTranslation&#39;
    }

    defaultConfig {
        applicationId &quot;rcm.samapp&quot;
        minSdkVersion 21
        targetSdkVersion 28
        versionName versionNameValue
        versionCode (versionCodeValue.toInteger() + 10000)
        vectorDrawables.useSupportLibrary = true

        multiDexEnabled true

        def backend = backend()

        resValue &#39;bool&#39;, &#39;debugMenu&#39;, &#39;false&#39;
    }

    dataBinding {
        enabled = true
    }

    kotlinOptions {
        jvmTarget = &#39;1.8&#39;
    }

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }


    packagingOptions {
        exclude &#39;lib/mips64/**&#39;
        exclude &#39;lib/mips/**&#39;
        exclude &#39;lib/armeabi/**&#39;
    }

    buildTypes {
        android.applicationVariants.all { variant -&gt;
            variant.getAssembleProvider().configure() {
                it.doFirst {
                   
           ...
                }

                it.doLast {
                    ...
                }
            }
        }

 
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;
            debuggable true
            testCoverageEnabled true
            applicationIdSuffix &quot;.debug.dev&quot;
            versionNameSuffix &quot;.debug.$currentBranchName&quot;
            signingConfig signingConfigs.debug
            buildConfigField &#39;boolean&#39;, &#39;SHOW_DEBUG_MENU&#39;, &#39;true&#39;
        }

        development.initWith(release)
        development {
            debuggable true
            applicationIdSuffix &#39;.debug&#39;
            versionNameSuffix &quot;.development.$currentBranchName&quot;
            signingConfig signingConfigs.debug

            buildConfigField &#39;boolean&#39;, &#39;SHOW_DEBUG_MENU&#39;, &#39;true&#39;
            resValues.remove &#39;debugMenu&#39;
            resValue &#39;bool&#39;, &#39;debugMenu&#39;, &#39;true&#39;

        }
    }

    sourceSets {
        debug.java.srcDirs        += &#39;src/environments_debug/java&#39;
        development.java.srcDirs  += &#39;src/environments_debug/java&#39;
     
        release.java.srcDirs      += &#39;src/environments_release/java&#39;
        debug {
            jniLibs.srcDir &#39;src/jniLibsDebug&#39;
        }
        development {
            jniLibs.srcDir &#39;src/jniLibsRelease&#39;
        }
        release {
            jniLibs.srcDir &#39;src/jniLibsRelease&#39;
        }
    }

    testOptions {
        animationsDisabled = true
        animationsDisabled true

        unitTests {
            includeAndroidResources = true
        }
    }
}

def backend() {
    return project.getProperties().get(&quot;backend&quot;)
}

ext {
      lifeCycle = &#39;2.2.0&#39;
    dagger = &#39;2.27&#39;
    retrofit = &#39;2.4.0&#39;
    room = &#39;2.2.5&#39;
    glide = &#39;4.11.0&#39;
    espresso = &#39;3.2.0&#39;
    databinding = &#39;4.0.0&#39;
    appCenterSdkVersion = &#39;3.2.1&#39;
}

dependencyCheck {
    // Only check for vulnerabilities in the dependencies of the production release
    scanConfigurations += &#39;releaseCompileClasspath&#39;
}

jacoco {
    toolVersion = &quot;$jacocoVersion&quot;
}

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
}

task jacocoTestReport(type: JacocoReport, dependsOn: [&#39;testDebugUnitTest&#39;, &#39;createDebugCoverageReport&#39;]) {
}

dependencies {
    releaseImplementation files(&#39;libs/libidpmobile.jar&#39;)
    developmentImplementation files(&#39;libs/libidpmobile.jar&#39;)
    debugImplementation files(&#39;libs/libidpmobile-debug.jar&#39;)

    if (enableHermes) {
        def hermesPath = &quot;../../node_modules/hermesvm/android/&quot;;
        debugImplementation files(hermesPath + &quot;hermes-debug.aar&quot;)
        releaseImplementation files(hermesPath + &quot;hermes-release.aar&quot;)
    } else {
        implementation jscFlavor
    }

    implementation &#39;com.android.support:appcompat-v7:27.1.1&#39;


	...implementations

 
    testImplementation &#39;junit:junit:4.13&#39;

}

apply from: file(&quot;../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle&quot;);
applyNativeModulesAppBuildGradle(project)
// THIS NEEDS TO BE IN THE BOTTOM
apply plugin: &#39;com.google.gms.google-services&#39;

答案1

得分: 0

你有一些带有applicationIdSuffix的自定义构建变体,它们会改变包名。你也应该在run-android命令中设置它们。

据我所理解,你需要运行development变体。所以设置为--variant developmentdevelopment变体中的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

huangapple
  • 本文由 发表于 2020年7月30日 22:07:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63174957.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定