简体   繁体   中英

AndroidStudio :Cannot resolve symbol 'MainActivity'.Using AndroidAnnotations

I've decided to use AndroidAnnotations with Android Studio, I wanted to implement it through Gradle.But I got an error "Cannot resolve symbol 'MainActivity_'less...Validate resource references inside Android XML files."

My Version:

targetSDKversion 22 + compileSdkVersion 22 + buildToolsVersion "22.0.1"

But when I configured Android Studio (1.4.1) and modified the AndroidManifest.XML configuration files,the project was prompted to go wrong.Without my pre-processed class from my MainActivity -> MainActivity_ .

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dimon.org.androidannotation" >

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity_" >  //here
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

I want to know what is the wrong.

Thank you !!!

Here are some code of the build.gradle(Module and Project).

EDIT

Sharing build.gradle

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.3.2'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.dimon.org.androidannotation"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'com.dimon.org.androidannotation'
    }
}

EDIT2

Root build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I think these build.gradle configurations are no problem,but just don't konw why will go wrong.

Thank you so much!!

My project had not generated MainActivity_ file in the generated/source/apt/debug directory after I Make Project.Why?

Table of Contents

I'm using following Versions:

  • Android Studio 1.4.1
  • Gradle version 1.3.0
  • android-apt 1.4
  • AndroidAnnotations Version 3.3.2

If there should be a solution to this problem please tell me! Thanks!!

ADD:

I finally succeeded in generating a MainActivity_ file. Because my original order precompiled error cause can not be generated .I actually made ​​a simple mistake, really is brain cramp. Thanks to every one who answered , feeling you help me eliminate confusion, thank you ! !

Use this .

activity android:name="com.dimon.org.androidannotation.MainActivity_"

Better Approach

  1. Change your class name (Refactor) and set MainActivity

Then

  • Rebuilding the project
  • Cleaning the project
  • Syncing with Gradle Files
  • Closing the Project, closing AS and relaunching / reopening
  • File > Invalidate Caches / Restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM