【问题标题】:AndroidStudio :Cannot resolve symbol 'MainActivity'.Using AndroidAnnotationsAndroidStudio:无法解析符号“MainActivity”。使用 AndroidAnnotations
【发布时间】:2015-10-30 14:10:31
【问题描述】:

我决定将AndroidAnnotations 与Android Studio 一起使用,我想通过Gradle 来实现它。但是我收到一个错误“无法解析符号'MainActivity_'less...验证Android XML 文件中的资源引用。”

我的版本:

targetSDKversion 22 + compileSdkVersion 22 + buildToolsVersion "22.0.1"

但是当我配置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>

我想知道怎么回事。

谢谢!!!

这是build.gradle(Module and Project)的一些代码。

编辑

共享 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
}

我觉得这些build.gradle配置没问题,就是不知道为什么会出错。

非常感谢!!

我的项目在我制作项目后没有在generated/source/apt/debug目录下生成MainActivity_文件。为什么?

Table of Contents

我正在使用以下版本:

  • Android Studio 1.4.1
  • Gradle 版本 1.3.0
  • android-apt 1.4
  • AndroidAnnotations 版本 3.3.2

如果应该有解决此问题的方法,请告诉我!谢谢!!

添加:

我终于成功生成了一个 MainActivity_ 文件。因为我原来的命令预编译错误导致无法生成。我居然犯了一个简单的错误,真的是脑筋急转弯。感谢每一个回答的人,感觉你帮我消除了困惑,谢谢! !

【问题讨论】:

  • 你的班级名称是什么MainActivity_MainActivity
  • 请提供 MainActivity_ 的包名,并确保将 Activity 扩展到此类
  • 你先做项目了吗? MainActivity_ 文件已生成,因此在第一次成功构建之前它不存在。
  • @IntelliJAmiya实际生成了MainActivity_文件,所以这个类名是MainActivity。由于Android Studio版本升级,导致部分配置生成选项消失。直接编译无法生成MainActivity_inteligentlu。
  • @WonderCsabo 哦!我终于成功生成了一个 MainActivity_ 文件。因为我原来的命令预编译错误导致无法生成。非常感谢您的帮助。我可以继续学习AndroidAnnotations这个框架。谢谢!!!

标签: java android android-studio android-gradle-plugin android-annotations


【解决方案1】:

使用这个。

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

更好的方法

  1. 更改你的类名(重构)并设置MainActivity

然后

  • 重建项目
  • 清理项目
  • 与 Gradle 文件同步
  • 关闭项目,关闭 AS 并重新启动/重新打开
  • 文件 > 使缓存无效/重新启动

【讨论】:

  • 我的项目在我制作项目后没有在generated -&gt; source -&gt; apt -&gt; debug 中生成MainActivity_ 文件。为什么?谢谢。
  • 文件 > 使缓存无效/重启有帮助!谢谢。
猜你喜欢
  • 2014-09-15
  • 1970-01-01
  • 2016-08-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 2018-11-11
相关资源
最近更新 更多