【问题标题】:Gradle + RoboBinding with AspectJ + Lombok are not compatible togetherGradle + RoboBinding 与 AspectJ + Lombok 不兼容
【发布时间】:2015-05-30 20:33:09
【问题描述】:

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

  • 龙目岛
  • RoboBinding 与 AspectJ
  • 匕首

为了将 RoboBinding 与 AspectJ 和 android 工具 1.1.0 一起使用,我使用 fix 编译了 aspectj-plugin。

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

我还为 Maven 找到了 Lombok and AspectJ workaurond,但我不知道这是否也可以与 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'
}

【问题讨论】:

    标签: android gradle aspectj lombok robobinding


    【解决方案1】:

    如果您想了解更多关于 Lombok 结合 AspectJ 的情况,请阅读my other answer 并点击那里的链接。

    【讨论】:

      猜你喜欢
      • 2015-09-30
      • 2020-11-19
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2017-08-30
      • 2020-07-23
      • 2018-08-07
      • 2014-05-08
      相关资源
      最近更新 更多