0

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'
Yogesh Devgun
  • 1,297
  • 1
  • 19
  • 36

1 Answers1

0

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

Vadim Goroshevsky
  • 1,486
  • 10
  • 19
  • I thought all AndroidManifest files are clubbed to one and react native uses that file, isn't it so? Thank you for sharing and explaining, yes it resolves the error for splashactivity, but now in logcat I get this error `Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.` But metro bundler is running in parallel and in there I get this error `No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator.` – Yogesh Devgun Aug 05 '20 at 08:39
  • This is not related to your question topic. You can take a look at https://stackoverflow.com/questions/55441230/unable-to-load-script-make-sure-you-are-either-running-a-metro-server-or-that-yo – Vadim Goroshevsky Aug 05 '20 at 09:24
  • I checked most of these answers but nothing worked. I can see bundle loading on url `http://localhost:8081/index.bundle?platform=android&dev=true&minify=false` but not through app – Yogesh Devgun Aug 05 '20 at 10:36
  • Feel free to create separate question for that problem – Vadim Goroshevsky Aug 05 '20 at 12:13
  • done https://stackoverflow.com/questions/63265776/running-rn-view-in-existing-android-app-gives-error-unable-to-load-script – Yogesh Devgun Aug 05 '20 at 13:28