简体   繁体   中英

How to add a .jar library to android studio project 1.2.2?

I have a library called ojdbc6.jar that i need to use to be able to connect to an Oracle 11g database. I've added the file into the libs folder, added to the project as a dependency with scope compile , but when i debug the application through USB using a branded phone, the app raises an exception saying that it can't find the specified class, loaded through Class.forName . Instead, using a custom rom (CM12.1) with root permissions, no exception is thrown. How should i have to add the library to the APK so that it can be found using every device?

This is the stack trace of the exception that gets raised:

07-08 14:50:27.749    9115-9223/? E/BYTES﹕ java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at java.lang.Class.forName(Class.java:216)
            at com.example.francesco.ferieepermessi.LoginActivity$LoginTask.doInBackground(LoginActivity.java:110)
            at com.example.francesco.ferieepermessi.LoginActivity$LoginTask.doInBackground(LoginActivity.java:104)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)
     Caused by: java.lang.VerifyError: oracle/jdbc/driver/OracleDriver
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at java.lang.Class.forName(Class.java:216)
            at com.example.francesco.ferieepermessi.LoginActivity$LoginTask.doInBackground(LoginActivity.java:110)
            at com.example.francesco.ferieepermessi.LoginActivity$LoginTask.doInBackground(LoginActivity.java:104)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)

Do the following

Right click on Module -> Open module settings -> Dependencies -> You will find your library. If not

Add your library in libs folder and then

Right Click libs folder ->Add as library ->select module in which you have to add library(select module and not project) ->OK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM