繁体   English   中英

将MySql与Android Studio连接

[英]Connecting MySql with Android Studio

好吧,当我放入MySQL连接器时,我有些错误,但我不知道为什么。

我在这里进行了研究(stackoverflow),我试图更改build.gradle应用程序或模块,但它不起作用。 如果有人知道这是什么问题,它将对我有很大帮助。。谢谢。

错误:

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.


Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

Android Studio中的错误

我将代码添加到:

build.gradle应用程序:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.example.informatica.xabiagame"
        minSdkVersion 15
        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'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    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.android.support.constraint:constraint-layout:1.0.0-alpha9'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.android.gms:play-services-ads:9.6.1'
    compile 'com.google.android.gms:play-services:9.6.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile project(':MySQL')
}

apply plugin: 'com.google.gms.google-services'

项目模块:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

MySQL模块:

configurations.maybeCreate("default")
artifacts.add("default", file('mysql-connector-java-5.1.37-bin.jar'))

我来晚了一点,但我刚刚找到了解决此问题的方法:

  1. MySQL连接器5.1是使用Java 8编译的。
  2. 即使是现在,Android Studio 2.3也不直接支持Java 8。
  3. 您可以在app / build.gradle中编写以下代码:

     android { defaultConfig { jackOptions { enabled true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } 

    https://developer.android.com/guide/platform/j8-jack.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM