首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gradle + RoboBinding与AspectJ + Lombok不兼容

Gradle + RoboBinding与AspectJ + Lombok不兼容
EN

Stack Overflow用户
提问于 2015-03-26 17:25:42
回答 1查看 1.8K关注 0票数 2

我想在Gradle上的Android项目中集成以下库:

  • 隆布克
  • RoboBinding与AspectJ
  • 短剑

为了将RoboBinding与AspectJ和android 1.1.0一起使用,我用这个修复编译了aspectj插件。

所有库都在使用一些编译时注释处理。我发现Lombok与AspectJ不兼容。我注意到来自RoboBinding的注释处理器正在使用apt,而lombok只在提供的情况下工作(Dagger对两者都使用)。

我还为Maven找到了Lombok和AspectJ工作光环,但我不知道它是否也可以与Gradle一起使用(如果是,我不知道如何使用)。

没有Lombok,项目正在编译和工作。您能帮助将Lombok和AspectJ与Gradle集成起来吗?

错误:

代码语言:javascript
复制
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

模块:

代码语言:javascript
复制
@Module(injects = MainActivity.class)
public class BinderModule {

    @Provides
    @Singleton
    BinderModel provideBinderModel() {
        return new BinderModel();
    }
}

模型:

代码语言:javascript
复制
@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;
    }
}

活性:

代码语言:javascript
复制
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());
    }
}

布局:

代码语言:javascript
复制
<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>

分级脚本:

代码语言:javascript
复制
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'
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-05 23:12:21

如果你想更多地了解隆布克的情况,结合AspectJ,请阅读我的另一个答案,也跟随那里的链接。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29285016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档