问题
I am learning the gradle and AndroidAnnotations framework in the android studio.
But I encounter the problems at the initial...= =
I create a new project using android studio .
Then I put the dependences about the AndroidAnnotations.
My app.gradle all below
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "yu.idv.androidannotationtest"
minSdkVersion 15
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'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'org.androidannotations:androidannotations-api:3.3.1'
}
Then I put the annotation common above of the Activity like below:
import org.androidannotations.annotations.EActivity;
@EActivity(R.layout.activity_main)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
}
....
But I compile my program, I didn't see the layout . My Layout just default code,
there have a "Hello world" TextView in the XML file.
What happen in my gradle or other setting in the AndroidStudio?
Thank you very much.
回答1:
You also have to add the processor as an apt dependency and a processing argument which tells AA the location of the manifest using the android-apt plugin. Also do not forgot to change your manifest to point to the generated Activity (underscore at end).
Check out the Gradle instructions:https://github.com/excilys/androidannotations/wiki/Building-Project-Gradle.
Or start from the example project:https://github.com/excilys/androidannotations/tree/develop/examples/gradle
So basically add these to your script, too:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'android-apt'
def AAVersion = '3.3.1'
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}
来源:https://stackoverflow.com/questions/31084613/android-setting-androidannotations-using-gradle-at-androidstudio-not-show-layout