简体   繁体   English

AndroidStudio:无法解析符号“MainActivity”。使用 AndroidAnnotations

[英]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."我决定在 Android Studio 中使用AndroidAnnotations ,我想通过 Gradle 实现它。但我收到一个错误“无法解析符号‘MainActivity_’less...验证 Android XML 文件中的资源引用。”

My Version:我的版本:

targetSDKversion 22 + compileSdkVersion 22 + buildToolsVersion "22.0.1" 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_ .但是当我配置Android Studio(1.4.1)并修改AndroidManifest.XML配置文件时,提示项目出错。没有我的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).下面是build.gradle(Module and Project) 的一些代码

EDIT编辑

Sharing build.gradle分享 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编辑2

Root build.gradle根构建.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.我认为这些build.gradle配置没有问题,只是不知道为什么会出错。

Thank you so much!!非常感谢!!

My project had not generated MainActivity_ file in the generated/source/apt/debug directory after I Make Project.Why?我的项目在Make Project后没有在generated/source/apt/debug目录下生成MainActivity_文件。为什么?

Table of Contents目录

I'm using following Versions:我正在使用以下版本:

  • Android Studio 1.4.1安卓工作室 1.4.1
  • Gradle version 1.3.0摇篮版本 1.3.0
  • android-apt 1.4 android-apt 1.4
  • AndroidAnnotations Version 3.3.2 AndroidAnnotations 版本 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.我终于成功生成了一个 MainActivity_ 文件。 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更改您的类名(重构)并设置MainActivity

Then然后

  • Rebuilding the project重建项目
  • Cleaning the project清理项目
  • Syncing with Gradle Files与 Gradle 文件同步
  • Closing the Project, closing AS and relaunching / reopening关闭项目,关闭 AS 并重新启动/重新打开
  • File > Invalidate Caches / Restart文件 > 使缓存无效/重新启动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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