1

我是 Android 开发的新手,我尝试在我的应用程序上实现蓝牙 LE 功能。我在使用 RXAndroidBLE 运行我的 android 项目时遇到了一些困难。这个库使用 lambda,我无法让它运行。

我已经更新了我的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.maxime.applicationtest"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
    compile "com.polidea.rxandroidble:rxandroidble:1.1.0"
}

当我尝试在 MainActivity 中运行以下代码时,会显示错误:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RxBleClient rxBleClient = RxBleClient.create(this);

        Subscription scanSubscription = rxBleClient.scanBleDevices()
                .subscribe(
                        rxBleScanResult -> {
                            // Process scan result here.
                            Log.e("DEVICE", rxBleScanResult.getBleDevice().getName());
                        },
                        throwable -> {
                            // Handle an error here.
                        }
                );

// When done, just unsubscribe.
        scanSubscription.unsubscribe();
    }

FATAL EXCEPTION: Thread-4847
    Process: com.example.maxime.applicationtest, PID: 27342
        java.lang.NoSuchMethodError: No virtual method com_polidea_rxandroidble_internal_radio_RxBleRadioImpl$$Lambda$1_lambda$new$0()V in class Lcom/polidea/rxandroidble/internal/radio/RxBleRadioImpl; or its super classes (declaration of 'com.polidea.rxandroidble.internal.radio.RxBleRadioImpl' appears in /data/app/com.example.maxime.applicationtest-1/base.apk)
        at com.polidea.rxandroidble.internal.radio.RxBleRadioImpl$$Lambda$1.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:818)

我不知道为什么会出错。

如果有人可以帮助我,那就太好了。谢谢!

4

3 回答 3

0

也有这个问题。但是仅仅删除 jackOptions 是行不通的。不得不将 retrolambda 添加到我的项目中。我的构建 gradle 现在看起来像这样:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.3.1'
    }
}

repositories {
    mavenLocal()
}

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.trump.islove"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile "com.polidea.rxandroidble:rxandroidble:1.1.0"
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    testCompile 'junit:junit:4.12'
}
于 2017-01-16T12:38:05.403 回答
0

我终于通过删除jackOptions找到了解决方案。现在它就像一个魅力。

于 2017-01-12T16:02:41.320 回答
0

您必须写入 build.gradle 文件:

apply plugin: 'me.tatarka.retrolambda'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.3.1'
    }
}
于 2017-01-26T08:59:31.070 回答