0

I am trying to connect to a database with Java from Android Studio.

When I create a brand new empty project and run it, the project runs fine. As soon as I paste mysql-connector-java-5.1.38-bin into the lib directory (app/lib) and then try to run the project, I get 2 errors.

Error:com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_74\bin\java.exe'' finished with non-zero exit value 1

I've also tried adding it as a dependency but I didn't think I needed to because {include=[*.jar], dir=libs} is already in the dependency list.

Thanks for reading

RON2015
  • 443
  • 3
  • 16

1 Answers1

0

Does JDBC not work with Android?

JDBC is infrequently used on Android, and I certainly would not recommend it.

IMHO, JDBC is designed for high-bandwidth, low-latency, highly-reliable network connections (e.g., desktop to database server, Web application server to database server). Mobile devices offer little of these, and none of them consistently.

If so, tell me what alternatives I should look into for remote MySQL database access.

Create a Web service around your database and access that from Android.

As side benefits, you improve security (vs. leaving your database open), can offload some business logic from the client, can better support other platforms (e.g., Web or Web-based mobile frameworks), etc.

Referenced from this answer

Android cannot connect directly to the database server. Therefore we need to create a simple web service that will pass the requests to the database and will return the response.

So my suggestion is do not use JDBC jar file in android.

Check this answer for more details of the Execution failed for task :app transformClassesWithDexForDebug.

Community
  • 1
  • 1
ELITE
  • 5,815
  • 3
  • 19
  • 29