活动类不存在-为什么?

时间:2018-10-27 17:24:36

标签: android android-activity manifest

我找不到Logcat报告活动类com.abc.marksix.SugarActivity不存在的原因。清单,Logcat,app / build.gradle和项目结构如下。你能帮忙吗?

代码:

Android清单:

<application
    android:allowBackup="true"
    android:name="SugarOrmTestApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.gms.ads.com.abc.marksix"
        android:value="ca-app-pub-xxx/xxx"
     />

    <activity
        android:name="com.abc.marksix.SugarActivity"
        android:screenOrientation="portrait"
        android:exported="true"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Logcat:

10/28 01:01:47: Launching app
$ adb push C:\Users\xxx\outputs\apk\debug\app-debug.apk /data/local/tmp/com.abc.marksix
$ adb shell pm install -t -r "/data/local/tmp/com.abc.marksix"
Success
APK installed in 2 s 777 ms
$ adb shell am start -n "com.abc.marksix/com.abc.marksix.SugarActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.abc.marksix/com.abc.marksix.SugarActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.abc.marksix/.SugarActivity }
Error type 3
Error: Activity class {com.abc.marksix/com.abc.marksix.SugarActivity} does not exist.

项目结构:

enter image description here

app / build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.abc.marksix"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:support-v4:28.1.1'
    implementation 'com.android.support:appcompat-v7:28.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

    implementation 'com.github.satyan:sugar:1.5'
    implementation 'com.parse:parse-android:1.13.0'
    implementation 'com.google.android.gms:play-services-ads:17.0.0'
    implementation 'com.adlocus:library:3.5.7@aar'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation files('src/main/java/com/abc/libs/jeval.jar')
    implementation files('src/main/java/com/abc/libs/jscience.jar')
}

2 个答案:

答案 0 :(得分:0)

您的代码工作正常,并且一切正确。您只需要做的是

首先,从IDE运行您的应用程序并安装它。
第二, 尝试从设备设置而非从启动器或adb卸载应用程序。


希望它能起作用!

答案 1 :(得分:0)

在我这边,我确实使用了Android Studio的“顶部菜单”:

文件和重新导入Gradle项目 建立和清理项目 建立和制作项目 运行应用程序(退出所有虚拟设备后)

,在测试了StackOverFlow中找到的所有解决方案后,它仍然可以正常工作

希望对您有帮助

请注意,Re-Import Gradle Project足够=),因为它似乎由其余部分自己完成