我想在Gradle下面的库中集成Android项目:
为了将RoboBinding与AspectJ和android工具1.1.0一起使用,我用这个fix编译了aspectj-plugin。
所有库都使用一些编译时注释处理。我发现Lombok与AspectJ不兼容。我注意到RoboBinding的注释处理器正在使用apt,而lombok仅使用提供的(Dagger适用于两者)。
我还发现了Lombok and AspectJ maven的工作,但我不知道这是否也可以与Gradle一起使用(如果是,我不知道怎么做)。
没有Lombok项目正在编译和工作。你能帮忙将Lombok和AspectJ与Gradle集成吗?
错误:
Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
:app:compileDebugAspectJ
warning You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ
error at model.setOutput(model.getInput());
D:\Projects\BinderExample\app\src\main\java\foo\binderexample\MainActivity.java:32:0::0 The method getInput() is undefined for the type BinderModel
Error:Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
Note: Start RoboBinding annotations processing...
error at model.setOutput(model.getInput());
D:\Projects\BinderExample\app\src\main\foo\binderexample\MainActivity.java:32:0::0 The method getInput() is undefined for the type BinderModel
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugAspectJ'.
> The method getInput() is undefined for the type BinderModel
模块:
@Module(injects = MainActivity.class)
public class BinderModule {
@Provides
@Singleton
BinderModel provideBinderModel() {
return new BinderModel();
}
}
型号:
@Data
@PresentationModel
public class BinderModel implements HasPresentationModelChangeSupport {
private final PresentationModelChangeSupport changeSupport = new PresentationModelChangeSupport(this);
private String input;
private String output;
@Override
public PresentationModelChangeSupport getPresentationModelChangeSupport() {
return changeSupport;
}
}
活动:
public class MainActivity extends Activity {
@Inject
BinderModel model;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ObjectGraph.create(new BinderModule()).inject(this);
View view = Binders.inflateAndBind(this, R.layout.activity_main, model);
setContentView(view);
ButterKnife.inject(this);
}
@OnClick(R.id.button)
void onButtonClick() {
model.setOutput(model.getInput());
}
}
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://robobinding.org/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:inputType="text"
bind:text="${input}"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/button"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
bind:text="{output}"/>
</LinearLayout>
Gradle脚本:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'org.robobinding:aspectj-plugin:0.8.3-fix'
}
}
apply plugin: 'com.android.application'
apply plugin: 'org.robobinding.android-aspectj'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "foo.binderexample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.jakewharton:butterknife:6.1.0'
//dagger
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
//lombok
provided 'org.projectlombok:lombok:1.16.2'
apt 'org.projectlombok:lombok:1.16.2'
//robobinding
compile('org.robobinding:robobinding:0.8.9:with-aop-and-dependencies') {
exclude group: 'com.google.guava', module: 'guava'
}
aspectPath('org.robobinding:robobinding:0.8.9:with-aop-and-dependencies') {
exclude group: 'com.google.guava', module: 'guava'
}
apt 'org.robobinding:codegen:0.8.9'
}