I'm trying to learn how to use the JDBC to connect a application to a MySQL database.
I'm using the Android Studio.
I downloaded "mysql-connector-java-5.1.37" from the MySQL website.
Just for put the "mysql-connector-java-5.1.37-bin.jar" in libs folder of a Hello World application and compile I receive :
Error:Execution failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1
the build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.myaplication.helloworld"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
}
Try to sync your project
Tools -> Android -> Sync Project with Gradle Files
And then rebuild your project:
build -> rebuild project
I had the same issue and the problem was in the mysql-connector-java-5.1.37.jar file. I downloaded an older version (mysql-connector-java-3.0.17-ga-bin.jar) from here and worked like a charm.
To get the connection use:
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connection = "jdbc:mysql://"+ your_ip + ":"+ your_port +"/"+ database_name;
conn = DriverManager.getConnection(connection, user, pass);
Just in case, don't forget to compile it in your build.gradle:
dependencies {
//other stuff
compile files('libs/mysql-connector-java-3.0.17-ga-bin.jar')
}
PD: This only works if you use the connection from and AsyncTask
Because Distributed mysql-connector-java-5.1.37-bin.jar is compiled for Java1.8, current Android dex compiler cannot recognize it.
$ javap -v com/mysql/jdbc/JDBC42Helper.class| grep "major version"
major version: 52
On the oher hand, mysql-connector-java-5.1.36.jar is compiled for Java1.6.
$ javap -v com/mysql/jdbc/JDBC4Connection.class |grep "major version"
major version: 50
5.1.37 supports JDBC4.2, so requires Java1.8.
Related
This error came up out of nowhere, until then everything worked fine for months.
Now even creating a new project results the same error without any modification.
flutter run ->
Using hardware rendering with device sdk gphone x86 arm. If you notice graphics artifacts, consider enabling software
rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.1.0.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.1.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 4.8s
Exception: Gradle task assembleDebug failed with exit code 1
app level build.gradle ->
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.utilapp"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
project level build.gradle ->
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
flutter doctor ->
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.1 20C69 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[!] Xcode - develop for iOS and macOS
! CocoaPods 1.7.5 out of date (1.10.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on
the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
Check your internet connection. This error appeared for me when the connection suddenly went down.
I would like to use some java 8 features in my app (namely the usage of a json library)
However, when I add
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
to my build.gradle the Gradle project sync failes:
A problem occurred configuring project ':app'.
java.lang.NullPointerException (no error message)
I am using Android studio on Ubuntu 19.04 with the following Java versions installed
wouter#Wouter-Laptop:~/Android/Sdk$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
wouter#Wouter-Laptop:~/Android/Sdk$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/javac to provide /usr/bin/javac (java
My build.gradle looks like
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "nl.wouter.cycleweatherapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'org.osmdroid:osmdroid-android:6.1.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
Removing the Java 1.8 part in the build.gradle file removes the error but gives no java 1.8 features.
Next to switching and installing java versions I have tried to invalidate and regenerate the gradle cache.
I have no clue how to proceed, can anybody help me?
I finally fixed it by installing a Ubuntu LTS in vitrualbox and using that to do the development
We are splitting our app into 32 and 64 bit versions as per Google's requirements. As part of this change, we started using the D8 compiler instead of the older DEX compiler. When we use the D8 compiler, our build time has increased from 6 to 20 minutes (we have a large app). We have done extensive research online and the only solution to that we have found to reduce build time is to disable desugaring. However, the app will not build if the desugaring is disabled.
Updating the gradle version to 5.6 from 5.5.1 has not solved our issues when we turn desugaring off. Neither has removing the .gradle and build directories and invalidating + restarting the app. We are using
Android Studio version 3.5.
Build error with android.enableD8.desugaring=false
> Task :app:compileRegionNaDebugAndroidTestJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Exception in thread "main" java.lang.TypeNotPresentException: Type org.gradle.internal.reflect.Instantiator not present
at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:54)
at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:406)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1623)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)
Caused by: java.lang.ClassNotFoundException: Class org.gradle.internal.reflect.Instantiator not found
at com.google.devtools.build.android.desugar.HeaderClassLoader.findClass(HeaderClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:83)
... 12 more
gradle.properties file
XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.caching=false
android.databinding.enableV2=true
android.enableD8.desugaring=false
build.gradle snippet
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
buildToolsVersion '27.0.3'
testInstrumentationRunner "com.appmps.mobileapp.EspressoTestRunner"
multiDexEnabled true
testApplicationId "com.appmps.mobileapp.test"
}
splits {
abi {
enable true
reset()
if (isEmulatorRun()) {
include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
} else {
include "armeabi-v7a", "arm64-v8a"
}
universalApk false
}
}
useLibrary 'org.apache.http.legacy'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
We would be thankful for suggestions on getting our app to build with desugaring disabled. We are also interested in any additional strategies for reducing build time related to using the D8 compiler.
Thank you!
When I open Android Studio my first time, I saw "AAPT2 error: check logs for details" this error.
When I check details wrote:
error: attribute
com.example.b3rk4.myapplication:layout_constraintBottom_toBottomOf'
not found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintLeft_toLeftOf' not
found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintRight_toRightOf' not
found.
error: attribute
'com.example.b3rk4.myapplication:layout_constraintTop_toTopOf' not
found.
Java compiler: (1 error) error: failed linking file resources.
What i tried already:
Open with administrator
Build->Clean Project and Build->Rebuild Project
Invalidate Caches / Restart
Add android.enableAapt2=false in gradle.properties (When i do this "AAPT2 error: check logs for details" error transforming to "Process 'command 'C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe'' finished with non-zero exit value 1" and when i look details:
No resource identifier found for attribute
'layout_constraintBottom_toBottomOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintLeft_toLeftOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintRight_toRightOf' in package
'com.example.b3rk4.myapplication'
No resource identifier found for attribute
'layout_constraintTop_toTopOf' in package
'com.example.b3rk4.myapplication'
Java compiler: (3 errors)
Caused by: java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: Error while executing
process
C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe
with arguments {package -f --no-crunch -I
C:\Users\b3rk4\AppData\Local\Android\Sdk\platforms\android-27\android.jar
-M \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
-S C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\merged\debug
-m -J \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\generated\source\r\debug
-F C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\debug\resources-debug.ap_
--custom-package com.example.b3rk4.myapplication -0 apk --preferred-density 420dpi --output-text-symbols \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\symbols\debug
--no-version-vectors}
Caused by: com.android.ide.common.process.ProcessException: Error
while executing process
C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe
with arguments {package -f --no-crunch -I
C:\Users\b3rk4\AppData\Local\Android\Sdk\platforms\android-27\android.jar
-M \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
-S C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\merged\debug
-m -J \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\generated\source\r\debug
-F C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\res\debug\resources-debug.ap_
--custom-package com.example.b3rk4.myapplication -0 apk --preferred-density 420dpi --output-text-symbols \?\C:\Users\b3rk4\Desktop\MyApplication\app\build\intermediates\symbols\debug
--no-version-vectors}
Caused by: org.gradle.process.internal.ExecException: Process 'command
'C:\Users\b3rk4\AppData\Local\Android\Sdk\build-tools\27.0.2\aapt.exe''
finished with non-zero exit value 1
Changed to classpath 'com.android.tools.build:gradle:3.0.0'
Changed to buildToolsVersion "27.0.2"
I installed Java jdk, Android Studio, Sdk thinks very carefully.
Added path C:\Users\b3rk4\AppData\Local\Android\Sdk\platform-tools and C:\Users\b3rk4\AppData\Local\Android\Sdk
I unistaled everythink and installed again be carefully and noting changed...
Can you help me please? I were using Android Studio normally 1 month ago and I format my computer and then I can't use any more
My build.gradle (project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle (Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.example.b3rk4.myapplication"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
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'
}
I use:
Windows 7 64 bit,
Android Studio 2.1.2
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode).
My app works fine on my mobile and on Android Emulator.
However when I tried to run debug mode on my Android phone nothing happened.
I made several breakpoints where the program has to stopb but it ignores my breakpoints.
Please help me, if I need to provide additional information let me know.
My build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.android.justjava"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
I recommend you to try like this:
Select debug Build Flavor.
Set break point at the code always execute.
ex) Activity's onCreate method.
Run as Debug. (Select Menu -> Run -> Debug in AndroidStudio)
Execution will be stopped at the break point.