1

My android app needs to do some work with SQL Server using JDBC, So I've added sqlljdbc42.jar file in module,

But I got error in Build - Gradle, Below is my Gradle Console :

:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42400Alpha1Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2400Alpha1Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
AGPBI: {"kind":"SIMPLE","text":"PARSE ERROR:","position":{},"original":"PARSE ERROR:"}
AGPBI: {"kind":"SIMPLE","text":"unsupported class file version 52.0","position":{},"original":"unsupported class file version 52.0"}
AGPBI: {"kind":"SIMPLE","text":"...while parsing com/microsoft/sqlserver/jdbc/ActivityCorrelator.class","position":{},"original":"...while parsing com/microsoft/sqlserver/jdbc/ActivityCorrelator.class"}
AGPBI: {"kind":"SIMPLE","text":"1 error; aborting","position":{},"original":"1 error; aborting"}

BUILD FAILED    
FAILURE: Build failed with an exception.

* What went wrong:
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_40\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

and in Gradle Build windows I got This :

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_40\bin\java.exe'' finished with non-zero exit value 1

Connections String is working fine and My MainActivity.java file contains :

    public class MainActivity extends ActionBarActivity {

        TextView tv;
        Connection DbConn;
        Statement stmt;
        ResultSet reset;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.textView);

            try {
                Log.e("Inside the Try Block", "Pre - Done");
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
                DbConn = DriverManager.getConnection("{connection string}");
                Log.e("Connection","open");
                stmt = DbConn.createStatement();
                reset = stmt.executeQuery(" select * from Members");
                tv.setText("User Name : "+reset.getString(1)+", Name : "+reset.getString(2));
                DbConn.close();
            } catch(Exception e) {
                Log.e("Error connection", "" + e.getMessage());
                e.printStackTrace();
            }

        }
}
N D
  • 3
  • 4
Nirav Madariya
  • 1,470
  • 2
  • 24
  • 37

1 Answers1

2

The error is caused due to mismatching bytecode versions of the compiler and the classes in the included .jar archive see got unsupported class file version 52 0 after including a module to a project for details

EDIT: using sqljdbc41.jar instead of sqljdbc42.jar should solve the issue

Community
  • 1
  • 1
Sakchham
  • 1,689
  • 12
  • 22
  • only .jar file I've added is sqljdbc42.jar and as per https://msdn.microsoft.com/en-us/library/ms378422(v=sql.110).aspx this, It uses JDK 1.8 and That's my JDK version. – Nirav Madariya Jun 29 '16 at 20:18
  • @NiravMadariya it depends upon the Target compatibility instead of installed version of the Java SDK. Unless you are working on Android Studio 2.1+ and targeting Android N you cannot build with Java 1.8 compliance bytecode. Below Android N the target compatibility can be either `1.7` or `1.6`. Therefore `sqljdbc41.jar` should be used. – Sakchham Jun 29 '16 at 20:43
  • Unfortunately, I'm targetting Android N. – Nirav Madariya Jun 29 '16 at 20:47
  • @NiravMadariya In AndroidStudio(only 2.1+) select the following menu Build -> Edit flavors -> Switch to Properties tab -> change the Target Compatibility to 1.8 or switch to `sqljdbc41.jar` – Sakchham Jun 29 '16 at 21:03