【问题标题】:How to Get Android Annotations Working in Studio 0.8.2如何在 Studio 0.8.2 中获取 Android 注释
【发布时间】:2014-08-07 15:56:13
【问题描述】:

我一直在尝试让 Android Annotations 运行我安装的 Android Studio 0.8.2,但无法正常运行。

这是我为设置它所做的工作......

在文件 > 设置 > 编译器 > 注释处理器 选择“启用注释处理” 处理器路径设置为“C:\software\android\androidannotations-3.0.1.jar;C:\software\android\androidannotations-api-3.0.1.jar”

将生成的源存储设置为“模块内容根” 目录设置为“gen/aa”和“gen/aa-test”

将 androidannotations-3.0.1.jar 文件放在项目的 libs 目录中。

我可以正确地将注释添加到文件中,自动完成会找到所有注释。

但是,当我将 AndroidManifest.xml 文件更改为使用 android:name 末尾的 _ 时,它显示为红色,并且不会启动应用程序。

然后,在 Launch Configurations 中将 Activity 更改为使用下划线后,它也失败并出现错误。

接下来的步骤?

    <activity
        android:name=".FlagActivity_"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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



@EActivity
public class FlagActivity extends Activity implements
      GooglePlayServicesClient.ConnectionCallbacks,
      GooglePlayServicesClient.OnConnectionFailedListener {

【问题讨论】:

    标签: android android-annotations


    【解决方案1】:

    我在 Android Studio 0.8.2 上运行了 Android 注释。

    首先,您不必指定特定的活动,只需选择“启动默认活动”即可。您的清单看起来不错。

    我发现你需要不时同步gradle,这样才能生成BlahActivity_。

    这是我的应用模块的 gradle 配置(仅限 Android 注释特定配置):

            buildscript {
                repositories {
                    mavenCentral()
                }
                dependencies {
                    classpath 'com.android.tools.build:gradle:0.12.+'
                    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
                }
            }
    
            apply plugin: 'android'
            apply plugin: 'android-apt'
    
            repositories {
                mavenCentral()
            }
    
            apply plugin: 'com.android.application'
    
            android {
    
                compileSdkVersion 20
                buildToolsVersion "20.0.0"
    
                defaultConfig {
                    applicationId "com.foo.androidapp"
                    minSdkVersion 16
                    targetSdkVersion 20
                    versionCode 1
                    versionName "1.0"
                }
    
                buildTypes {
                    release {
                        runProguard false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
    
                // AA: if you are going to use the spring rest template with AA
                packagingOptions {
                    exclude 'META-INF/ASL2.0'
                    exclude 'META-INF/LICENSE'
                    exclude 'META-INF/license.txt'
                    exclude 'META-INF/NOTICE'
                    exclude 'META-INF/notice.txt'
                }
    
                productFlavors {
    
                    production {
                        packageName = 'com.foo.androidapp'
                    }
    
                    development {
                        packageName = 'com.foo.androidapp.dev'
                    }
    
                }
            }
    
            dependencies {
                // AA imports (also enables REST support w AA)!!
                compile fileTree(dir: 'libs', include: ['*.jar'])
                compile 'org.androidannotations:androidannotations-api:3.0+'
                compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
                compile 'com.fasterxml.jackson.core:jackson-databind:2.4.1.3'
                compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
                apt 'org.androidannotations:androidannotations:3.0+'
    
            }
    
            apt {
                arguments {
                    androidManifestFile variant.processResources.manifestFile
    
                    resourcePackageName "com.foo.androidapp"
    
                    // You can set optional annotation processing options here, like these commented options:
                    // logLevel 'INFO'
                    // logFile '/var/log/aa.log'
                }
            }
    

    【讨论】:

    • 很好,它开始工作了。谢谢!一个问题,您是否注意到构建过程和运行命令花费的时间明显更长?比如从 5 秒到 60 秒。
    • 嗯...我经常使用 AA,几乎我所有的课程都使用注释,但是应用程序 atm 并没有那么大。然而,令人讨厌的是,我经常不得不“刷新 gradle”以便生成 BlahAcitivty_。
    【解决方案2】:

    您必须将库路径添加到您的 Android Studio 项目的特定模块中的 build.gradle 文件中

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    

    基本上你必须确保你的 libs 文件夹中的依赖项实际上正在编译

    我不确定下划线的困境

    【讨论】:

    • 默认包含libs文件夹
    • @bluedevil2k 您是否添加了classpath ‘com.android.tools.build:gradle:0.9.+’w,如 cmets 中所述,jayway.com/2014/02/21/… 随着时间的推移,似乎有越来越多的额外语义内容要添加到 build.gradle 文件中较新版本的 Android Studio 和 IntelliJ
    【解决方案3】:

    如果您对“未找到活动”有疑问。 您只需要通过 Tools->Android->Sync Project 与 Gradle 文件同步 Gradle。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-21
      • 2016-01-26
      • 2014-10-13
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      相关资源
      最近更新 更多