在android中添加signalr Dependency会产生库依赖性错误

问题描述 投票:1回答:2

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

我有这个错误。

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.

Gradle同步成功。但建筑失败了。

请注意,我已经在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天但没有成功,非常感谢:-)

c# android signalr
2个回答
0
投票

在你的gradle中添加:

可能有些依赖项可以用Java 8编译,尤其不适用于Android。尝试将该依赖项切换为旧版本。我不确切知道你要降级哪个库。

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

编辑:

改变这个:

classpath 'com.android.tools.build:gradle:2.2.3'

classpath 'com.android.tools.build:gradle:3.0.1'

0
投票

回答我自己的问题。

我试过的解决方案,经过3天的奋斗,它正在为我工​​作。从这里下载jar文件https://www.dropbox.com/sh/xcccz4gwjnxuiz8/AAClkwO_6KrbbyMclgD2ae_pa?dl=0来自microsoft网站的官方依赖对我不起作用。

下载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'
}
© www.soinside.com 2019 - 2024. All rights reserved.