在Android中添加singalr依赖关系会导致库依赖关系错误

时间:2019-03-23 07:39:16

标签: c# android signalr

在添加来自微软官方网站的依赖关系后,我正在android上使用 signalr compile 'com.microsoft.signalr:signalr:1.0.0'

我遇到此错误。

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

分级同步成功。但建设失败。

请注意,我已经在app.gradle文件中添加了这些行,但是没有成功。

compileOptions {
   sourceCompatibility JavaVersion.VERSION_1_7
   targetCompatibility JavaVersion.VERSION_1_7
}

这是我的gradle文件。

android {
    compileSdkVersion 27
    buildToolsVersion "28.0.3"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.example.adnanshaukat.myapplication"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled  true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

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'
    })


    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
    compile "com.android.support:appcompat-v7:27.0.1"
    compile "com.android.support:design:27.0.1"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.android.support:support-v4:27.0.1'
    compile 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
    compile 'com.jaredrummler:material-spinner:1.3.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.microsoft.signalr:signalr:1.0.0'
    testCompile 'junit:junit:4.12'
}

模块gradle文件

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven{
            url 'https://jitpack.io'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

请帮助我已经尝试了3天,但没有成功,将非常感激:-)

2 个答案:

答案 0 :(得分:0)

将此添加到您的i中:

可能有些依赖项可以使用Java 8进行编译,尤其不适用于Android。尝试将该依赖项切换到旧版本。我不知道您必须降级哪个库。

var dropdownBtns = document.getElementsByClassName("dropdown-btn");

for (let i = 0; i < dropdownBtns.length; i++) {
    dropdownBtns[i].addEventListener('click', function() {
        let panel = this.nextElementSibling;
        panel.classList.toggle('active-dropdown');
    });
}

编辑:

更改此内容:

gradle

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

答案 1 :(得分:0)

回答我自己的问题。

我尝试过的解决方案,经过3天的奋斗,它一直对我有效。 从此处https://www.dropbox.com/sh/xcccz4gwjnxuiz8/AAClkwO_6KrbbyMclgD2ae_pa?dl=0下载jar文件 微软网站上的官方依赖性对我不起作用。

下载 signalr-client-sdk.jar signalr-client-sdk-android.jar 并将它们放置在 app / libs 文件夹中

我更新的gradle文件如下所示

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "28.0.3"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.example.adnanshaukat.myapplication"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled  true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

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'
    })


    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
    compile "com.android.support:appcompat-v7:27.0.1"
    compile "com.android.support:design:27.0.1"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.android.support:support-v4:27.0.1'
    compile 'com.github.ViksaaSkool:AwesomeSplash:v1.0.0'
    compile 'com.google.android.gms:play-services:11.0.4'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
    compile 'com.jaredrummler:material-spinner:1.3.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile files('libs/signalr-client-sdk.jar')
    compile files('libs/signalr-client-sdk-android.jar')
    testCompile 'junit:junit:4.12'
}