javascript - 活动类 {rcm.samapp/com.comp.android.ui....} 不存在
问题描述
我正在尝试集成反应本机和本机 android 应用程序。
应用程序 build.gradle 中的 applicationId 是rcm.samapp
清单标签中的包是com.comp.android
.
SplashActivity.kt 中的第 1 行是package com.comp.android.ui
活动是清单看起来像:
<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>
遵循官方 RN 文档后,当我尝试通过react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity
命令运行它时,它会抛出此错误:
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.
可能是什么原因和解决方法?
构建.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'
解决方案
您有一些自定义构建变体applicationIdSuffix
正在更改包名称。您也应该在run-android
命令中设置它们。
据我了解,您需要运行development
变体。所以设置--variant development
。applicationIdSuffix
在development
变体中是.debug
. 将其指定为--appIdSuffix debug
。
变体的完整命令development
是:react-native run-android --appId rcm.samapp --main-activity ui.SplashActivity --variant development --appIdSuffix debug
推荐阅读
- java - 在 android studio 的选项卡布局中看不到小部件
- c# - 在带有 ClosedXML 的列验证中使用 INDIRECT
- javascript - 通过单击按钮从浏览器下载任何文件
- python - 使用 QThread 将 Pyqt5 程序转换为 Pyside6
- svg - 鼠标移动后悬停时的 SVG 自定义工具提示
- amazon-web-services - 存储游戏分数的 Amazon RDS 或 S3 Bucket?
- javascript - 反应错误类型错误:无法读取未定义的属性“名称”
- java - Android 应用程序在使用 OpenCV 中的任何内容时崩溃
- java - 这个 ConcurrentLinkedQueue/wait/notify 算法是否正确?
- javascript - Atom:将代码放在正文 HTML 上后,Javascript 显示“ReferenceError:文档未定义”