java - 连接MySql和Android Studio

标签 java android mysql android-studio localhost

嗯,当我放置 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

Errors in 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

关于java - 连接MySql和Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40233354/

相关文章:

java - 通用类型和自己的比较器

java - 字符串到字符数组在 Visual Studio 和 Android Studio 中返回不同的结果

java - 带通知的后台服务

android - Marquee 在微调器 Android 中不工作

javascript - 在 WebView 中通过 js 注入(inject)设置 TextBox 值

mysql - INNER JOIN 之前的 WHERE 子句

mysql - mysql左连接问题

java - ?父类(super class)型 Java 泛型

安卓 : Make 2 services communicate

mysql - 为什么 MySQL 没有按预期 ORDER?