Android 注释 - 找不到默认活动



我在 Android Studio 中使用 android 注释,但在运行时(成功构建后)不断收到错误,找不到默认活动。它来来去去,有时它只需要重新启动Android Studio,有时需要清理和重建,有时它只是不会消失(我不知道如何始终如一地重现它)。

我知道事情有点问题,但是如何始终如一地重现此错误,以及每次出现时删除它的可靠步骤

    <activity
        android:name="com.example.somghosh.earthmiles.views.MainActivity_"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

build.girdle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
repositories {
    mavenCentral()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"
    defaultConfig {
        applicationId "com.example.somghosh.earthmiles"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}
apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "com.example.somghosh.earthmiles"
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    apt "org.androidannotations:androidannotations:3.2"
    compile 'org.androidannotations:androidannotations-api:3.2'
    //Core
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
    //Optional for built-in cards
    compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
    //Optional for RecyclerView
    compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
    //Optional for staggered grid view
    compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
    //Optional for drag and drop
    compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
    compile 'in.srain.cube:ultra-ptr:1.0.5'
    compile 'it.neokree:MaterialTabs:0.10'
    compile 'com.android.support:support-annotations:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.squareup.retrofit:retrofit:1.8.0'
    compile 'com.google.code.gson:gson:2.3.1'
    //    compile 'com.google.code.gson:gson:1.7.2'
    //    compile 'org.parceler:parceler:0.2.15'
    // new for fix
    compile 'org.parceler:parceler-api:0.2.16-SNAPSHOT'
    provided 'org.parceler:parceler:0.2.16-SNAPSHOT'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.github.siyamed:android-shape-imageview:0.9.2'
    compile 'com.squareup.picasso:picasso:2.4.0'
    provided 'org.projectlombok:lombok:1.14.8'
    apt "org.projectlombok:lombok:1.14.8"
    compile 'com.github.talenguyen:prettysharedpreferences:1.0.2'
    compile('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
        // exclusion is not neccessary, but generally a good idea.
        exclude group: 'com.google.android', module: 'support-v4'
    }
    compile 'com.afollestad:material-dialogs:0.4.7'
//    compile 'commons-beanutils:commons-beanutils-core:1.8.3'
}

这似乎是Android Studio的一个错误,我也有。它似乎忘记了 AA 生成的构建目录,因此无法解析其中生成的类。

最快的解决方案是打开构建变体(查看 -> 工具窗口 ->构建变体,如果它还没有在 UI 上),将模块(应用程序)的构建变体从调试更改为发布,然后再更改回调试。Android Studio 将选取更改并再次解决缺少的类。

编辑:有一个更好的解决方案,检查我的另一个答案。

只需将 apt 插件从 1.2 更改为 1.3 或更高即可解决问题!

classpath "com.neenbedankt.gradle.plugins:android-apt:1.4"

最新更新