在 android 中添加 singalr 依赖会导致库依赖错误
Adding singalr Dependency in android gives library dependency error
我在 android 上使用 signalr,从 Microsoft 官方网站 添加依赖项后
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.
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 天但没有成功,将非常感谢:-)
将此添加到您的 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'
回答我自己的问题。
我尝试过的解决方案,经过 3 天的努力,它对我有用。
从这里下载 jar 文件 https://www.dropbox.com/sh/xcccz4gwjnxuiz8/AAClkwO_6KrbbyMclgD2ae_pa?dl=0
来自微软网站的官方依赖对我不起作用。
下载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'
}
我在 android 上使用 signalr,从 Microsoft 官方网站 添加依赖项后
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.
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 天但没有成功,将非常感谢:-)
将此添加到您的 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'
回答我自己的问题。
我尝试过的解决方案,经过 3 天的努力,它对我有用。 从这里下载 jar 文件 https://www.dropbox.com/sh/xcccz4gwjnxuiz8/AAClkwO_6KrbbyMclgD2ae_pa?dl=0 来自微软网站的官方依赖对我不起作用。
下载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'
}