Reputation: 41
I have been trying to install the jdbc driver in android studio to connect to a mysql database.
I have tried to do it in 2 ways which were already explained on stackoverflow but they don't work anymore. Both times I used the jar-file I got after unzipping the file I downloaded here.
The first way was by copying the jar file into the libs folder and adding it as library with a right-mouse click.
The second try was by following this tutorial: How to Mysql JDBC Driver to android studio.
I can always build my app but when I try to run it on the emulator or on an extern android device I got these errors:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.app.app/com.app.app.LoginScreen}: java.lang.ClassNotFoundException: Didn't find class "com.app.app.LoginScreen" on path: DexPathList[[zip file "/data/app/com.app.app-XrBFCO1PMt-F537ZaZs6PQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.app-XrBFCO1PMt-F537ZaZs6PQ==/lib/x86, /system/lib, /vendor/lib]]
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app.app.LoginScreen" on path: DexPathList[[zip file "/data/app/com.app.app-XrBFCO1PMt-F537ZaZs6PQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.app.app-XrBFCO1PMt-F537ZaZs6PQ==/lib/x86, /system/lib, /vendor/lib]]
This is the build.gradle file with the library installed the second way: apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "app"
minSdkVersion 26
targetSdkVersion 26
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 'com.android.support:support-annotations:27.1.1'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':mysql-connector-java-8.0.11')
}
Litte sidenote: I know that there is no error in my code because I tested it int he Intellij IDE where I did succeed to install the driver.
I hope anybody of you guys can help me. You would rock!
Upvotes: 3
Views: 10762
Reputation: 162
YourApp\app\libs
In the Gradle file add:
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
.
.
.
implementation files('libs/YourFILE')
}
Add your class. Well that worked for me.
Upvotes: 2