0

我是 Android 开发的新手,在使用注释时遇到了问题。我向 Maven 添加了依赖项:

<!-- Android annotations and AA API dependecies start -->
      <dependency>
          <groupId>com.googlecode.androidannotations</groupId>
          <artifactId>androidannotations</artifactId>
      </dependency>
      <dependency>
          <groupId>com.googlecode.androidannotations</groupId>
          <artifactId>androidannotations-api</artifactId>
      </dependency>
      <!-- Android annotations and AA API dependecies end -->

注释处理器配置正确,我有我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.gl.discovercity" android:versionCode="1" android:versionName="1.0-SNAPSHOT">

  <uses-sdk android:minSdkVersion="8"
            android:targetSdkVersion="16" />

  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".SplashScreenActivity_">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>

</manifest>

当我尝试启动我的应用程序时,我有下一个堆栈跟踪:

05-03 10:12:08.010: ERROR/AndroidRuntime(1246): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gl.discovercity/com.gl.discovercity.SplashScreenActivity_}: java.lang.ClassNotFoundException: com.gl.discovercity.SplashScreenActivity_ in loader dalvik.system.PathClassLoader[/data/app/com.gl.discovercity-2.apk]
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.ClassNotFoundException: com.gl.discovercity.SplashScreenActivity_ in loader dalvik.system.PathClassLoader[/data/app/com.gl.discovercity-2.apk]
        at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
        ... 11 more

最后,我有一个活动:

@EActivity(R.layout.main)
public class SplashScreenActivity extends Activity {
}

有人可以帮助我吗?:"(

4

2 回答 2

0

使用 android 时,您不应再使用 maven。将 gradle 和以下 build.gradle 文件用于工作的 android 注释项目:

全球应该看起来像

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // APT Dependency for annotation processing
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

allprojects {
    repositories {
        mavenCentral()
        mavenLocal()
    }
}

主模块是这样的:

apply plugin: 'com.android.application'

// apply apt plugin from global gradle file
apply plugin: 'android-apt'

// Tell apt where to find sources
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'de.company.android.app'
    }
}


android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "de.company.android.app"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "0.0.1"        
    }
}

dependencies {
    // Android Anotations dependencies equaling the one's from maven
    apt "org.androidannotations:androidannotations:3.2"
    compile 'org.androidannotations:androidannotations-api:3.2'
}
于 2015-01-26T10:09:49.550 回答
0

您需要添加“.apt_generated”目录,或者 AA 将其生成的源输出到项目设置 -> 模块 -> module_in_question 中的“源”目录的任何位置。

于 2013-05-29T18:05:13.677 回答