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

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

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 {

  1. compileSdkVersion 29
  2. def versionNameValue = System.getProperty("suppliedVersionName", "1.0.0")
  3. def versionCodeValue = System.getProperty("suppliedVersionCode", calculatedVersionCode)
  4. packagingOptions {
  5. pickFirst '**/*.so'
  6. }
  7. dexOptions {
  8. javaMaxHeapSize "4g"
  9. }
  10. lintOptions {
  11. abortOnError false
  12. disable 'MissingTranslation'
  13. }
  14. defaultConfig {
  15. applicationId "rcm.samapp"
  16. minSdkVersion 21
  17. targetSdkVersion 28
  18. versionName versionNameValue
  19. versionCode (versionCodeValue.toInteger() + 10000)
  20. vectorDrawables.useSupportLibrary = true
  21. multiDexEnabled true
  22. def backend = backend()
  23. resValue 'bool', 'debugMenu', 'false'
  24. }
  25. dataBinding {
  26. enabled = true
  27. }
  28. kotlinOptions {
  29. jvmTarget = '1.8'
  30. }
  31. compileOptions {
  32. targetCompatibility JavaVersion.VERSION_1_8
  33. sourceCompatibility JavaVersion.VERSION_1_8
  34. }
  35. packagingOptions {
  36. exclude 'lib/mips64/**'
  37. exclude 'lib/mips/**'
  38. exclude 'lib/armeabi/**'
  39. }
  40. buildTypes {
  41. android.applicationVariants.all { variant ->
  42. variant.getAssembleProvider().configure() {
  43. it.doFirst {
  44. ...
  45. }
  46. it.doLast {
  47. ...
  48. }
  49. }
  50. }
  51. debug {
  52. minifyEnabled false
  53. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  54. debuggable true
  55. testCoverageEnabled true
  56. applicationIdSuffix ".debug.dev"
  57. versionNameSuffix ".debug.$currentBranchName"
  58. signingConfig signingConfigs.debug
  59. buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
  60. }
  61. development.initWith(release)
  62. development {
  63. debuggable true
  64. applicationIdSuffix '.debug'
  65. versionNameSuffix ".development.$currentBranchName"
  66. signingConfig signingConfigs.debug
  67. buildConfigField 'boolean', 'SHOW_DEBUG_MENU', 'true'
  68. resValues.remove 'debugMenu';
  69. resValue 'bool', 'debugMenu', 'true';
  70. }
  71. }
  72. sourceSets {
  73. debug.java.srcDirs += 'src/environments_debug/java';
  74. development.java.srcDirs += 'src/environments_debug/java';
  75. release.java.srcDirs += 'src/environments_release/java';
  76. debug {
  77. jniLibs.srcDir 'src/jniLibsDebug';
  78. }
  79. development {
  80. jniLibs.srcDir 'src/jniLibsRelease';
  81. }
  82. release {
  83. jniLibs.srcDir 'src/jniLibsRelease';
  84. }
  85. }
  86. testOptions {
  87. animationsDisabled = true;
  88. animationsDisabled true;
  89. unitTests {
  90. includeAndroidResources = true;
  91. }
  92. }

}

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');

  1. if (enableHermes) {
  2. def hermesPath = "../../node_modules/hermesvm/android/";
  3. debugImplementation files(hermesPath + "hermes-debug.aar");
  4. releaseImplementation files(hermesPath + "hermes-release.aar");
  5. } else {
  6. implementation jscFlavor;
  7. }
  8. implementation 'com.android.support:appcompat-v7:27.1.1';
  9. ...implementations
  10. 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:

  1. &lt;activity
  2. android:name=&quot;.ui.SplashActivity&quot;
  3. android:screenOrientation=&quot;portrait&quot;&gt;
  4. &lt;intent-filter&gt;
  5. &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  6. &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
  7. &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
  8. &lt;/intent-filter&gt;
  9. &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:

  1. Starting: Intent { cmp=rcm.samapp/com.comp.android.ui.SplashActivity }
  2. Error type 3
  3. Error: Activity class {rcm.samapp/com.comp.android.ui.SplashActivity} does not exist.

What can be the reason and fix?

build.gradle

  1. apply plugin: &#39;com.android.application&#39;
  2. apply plugin: &#39;kotlin-android&#39;
  3. apply plugin: &#39;kotlin-kapt&#39;
  4. apply plugin: &#39;kotlin-android-extensions&#39;
  5. apply from: &#39;appcenter.gradle&#39;
  6. apply from: &#39;version.gradle&#39;
  7. apply plugin: &#39;jacoco&#39;
  8. apply plugin: &#39;org.owasp.dependencycheck&#39;
  9. apply from: &#39;checkstyle.gradle&#39;
  10. project.afterEvaluate {
  11. preBuild.dependsOn &#39;checkstyle&#39;
  12. }
  13. repositories {
  14. flatDir {
  15. dirs &#39;libs&#39;
  16. }
  17. }
  18. project.ext.react = [
  19. entryFile: &quot;index.js&quot;,
  20. enableHermes: false, // clean and rebuild if changing
  21. ]
  22. def jscFlavor = &#39;org.webkit:android-jsc:+&#39;
  23. def enableHermes = project.ext.react.get(&quot;enableHermes&quot;, false);
  24. dependencyCheck {
  25. scanConfigurations += &#39;releaseCompileClasspath&#39;
  26. }
  27. android {
  28. compileSdkVersion 29
  29. def versionNameValue = System.getProperty(&quot;suppliedVersionName&quot;, &quot;1.0.0&quot;)
  30. def versionCodeValue = System.getProperty(&quot;suppliedVersionCode&quot;, calculatedVersionCode)
  31. packagingOptions {
  32. pickFirst &#39;**/*.so&#39;
  33. }
  34. dexOptions {
  35. javaMaxHeapSize &quot;4g&quot;
  36. }
  37. lintOptions {
  38. abortOnError false
  39. disable &#39;MissingTranslation&#39;
  40. }
  41. defaultConfig {
  42. applicationId &quot;rcm.samapp&quot;
  43. minSdkVersion 21
  44. targetSdkVersion 28
  45. versionName versionNameValue
  46. versionCode (versionCodeValue.toInteger() + 10000)
  47. vectorDrawables.useSupportLibrary = true
  48. multiDexEnabled true
  49. def backend = backend()
  50. resValue &#39;bool&#39;, &#39;debugMenu&#39;, &#39;false&#39;
  51. }
  52. dataBinding {
  53. enabled = true
  54. }
  55. kotlinOptions {
  56. jvmTarget = &#39;1.8&#39;
  57. }
  58. compileOptions {
  59. targetCompatibility JavaVersion.VERSION_1_8
  60. sourceCompatibility JavaVersion.VERSION_1_8
  61. }
  62. packagingOptions {
  63. exclude &#39;lib/mips64/**&#39;
  64. exclude &#39;lib/mips/**&#39;
  65. exclude &#39;lib/armeabi/**&#39;
  66. }
  67. buildTypes {
  68. android.applicationVariants.all { variant -&gt;
  69. variant.getAssembleProvider().configure() {
  70. it.doFirst {
  71. ...
  72. }
  73. it.doLast {
  74. ...
  75. }
  76. }
  77. }
  78. debug {
  79. minifyEnabled false
  80. proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;
  81. debuggable true
  82. testCoverageEnabled true
  83. applicationIdSuffix &quot;.debug.dev&quot;
  84. versionNameSuffix &quot;.debug.$currentBranchName&quot;
  85. signingConfig signingConfigs.debug
  86. buildConfigField &#39;boolean&#39;, &#39;SHOW_DEBUG_MENU&#39;, &#39;true&#39;
  87. }
  88. development.initWith(release)
  89. development {
  90. debuggable true
  91. applicationIdSuffix &#39;.debug&#39;
  92. versionNameSuffix &quot;.development.$currentBranchName&quot;
  93. signingConfig signingConfigs.debug
  94. buildConfigField &#39;boolean&#39;, &#39;SHOW_DEBUG_MENU&#39;, &#39;true&#39;
  95. resValues.remove &#39;debugMenu&#39;
  96. resValue &#39;bool&#39;, &#39;debugMenu&#39;, &#39;true&#39;
  97. }
  98. }
  99. sourceSets {
  100. debug.java.srcDirs += &#39;src/environments_debug/java&#39;
  101. development.java.srcDirs += &#39;src/environments_debug/java&#39;
  102. release.java.srcDirs += &#39;src/environments_release/java&#39;
  103. debug {
  104. jniLibs.srcDir &#39;src/jniLibsDebug&#39;
  105. }
  106. development {
  107. jniLibs.srcDir &#39;src/jniLibsRelease&#39;
  108. }
  109. release {
  110. jniLibs.srcDir &#39;src/jniLibsRelease&#39;
  111. }
  112. }
  113. testOptions {
  114. animationsDisabled = true
  115. animationsDisabled true
  116. unitTests {
  117. includeAndroidResources = true
  118. }
  119. }
  120. }
  121. def backend() {
  122. return project.getProperties().get(&quot;backend&quot;)
  123. }
  124. ext {
  125. lifeCycle = &#39;2.2.0&#39;
  126. dagger = &#39;2.27&#39;
  127. retrofit = &#39;2.4.0&#39;
  128. room = &#39;2.2.5&#39;
  129. glide = &#39;4.11.0&#39;
  130. espresso = &#39;3.2.0&#39;
  131. databinding = &#39;4.0.0&#39;
  132. appCenterSdkVersion = &#39;3.2.1&#39;
  133. }
  134. dependencyCheck {
  135. // Only check for vulnerabilities in the dependencies of the production release
  136. scanConfigurations += &#39;releaseCompileClasspath&#39;
  137. }
  138. jacoco {
  139. toolVersion = &quot;$jacocoVersion&quot;
  140. }
  141. tasks.withType(Test) {
  142. jacoco.includeNoLocationClasses = true
  143. }
  144. task jacocoTestReport(type: JacocoReport, dependsOn: [&#39;testDebugUnitTest&#39;, &#39;createDebugCoverageReport&#39;]) {
  145. }
  146. dependencies {
  147. releaseImplementation files(&#39;libs/libidpmobile.jar&#39;)
  148. developmentImplementation files(&#39;libs/libidpmobile.jar&#39;)
  149. debugImplementation files(&#39;libs/libidpmobile-debug.jar&#39;)
  150. if (enableHermes) {
  151. def hermesPath = &quot;../../node_modules/hermesvm/android/&quot;;
  152. debugImplementation files(hermesPath + &quot;hermes-debug.aar&quot;)
  153. releaseImplementation files(hermesPath + &quot;hermes-release.aar&quot;)
  154. } else {
  155. implementation jscFlavor
  156. }
  157. implementation &#39;com.android.support:appcompat-v7:27.1.1&#39;
  158. ...implementations
  159. testImplementation &#39;junit:junit:4.13&#39;
  160. }
  161. apply from: file(&quot;../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle&quot;);
  162. applyNativeModulesAppBuildGradle(project)
  163. // THIS NEEDS TO BE IN THE BOTTOM
  164. 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:

确定