仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述通过在Android中实现Proguard,使用JDBC在Asynctask中崩溃相关的知识,希望能为你提供帮助。
我的应用程序之前工作正常,但在我的项目中启用ProGuard后,应用程序立即在“release”和“debug”apk中崩溃。我也禁用proguard并再次尝试它,它的工作原理。
现在我的问题是如何在我的项目中使用jdbc以及proguard,这可能吗?
这是我的调试
E/androidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.aileen.rotaractclub, PID: 6131
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ExceptionInInitializerError
at com.b.a.bq.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at com.example.aileen.rotaractclub.b.a.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <
init>
[class java.lang.String, int, class java.util.Properties, class java.lang.String, class java.lang.String]
at com.b.a.o.<
clinit>
(Unknown Source)
at com.b.a.bq.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at com.example.aileen.rotaractclub.b.a.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoSuchMethodException: <
init>
[class java.lang.String, int, class java.util.Properties, class java.lang.String, class java.lang.String]
at java.lang.Class.getConstructor(Class.java:528)
at java.lang.Class.getConstructor(Class.java:492)
at com.b.a.o.<
clinit>
(Unknown Source)
at com.b.a.bq.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:179)
at java.sql.DriverManager.getConnection(DriverManager.java:213)
at com.example.aileen.rotaractclub.b.a.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.a(Unknown Source)
at com.example.aileen.rotaractclub.b.a$c.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
这是我的AsyncTask
//Deleting Announcement
public class deleting extends AsyncTask<
String,String,String>
{
Boolean Connection = false;
Boolean isSuccess = false;
ProgressDialog progress;
String title;
String ids;
public deleting(String aydi,String titulo)
{ids=aydi;
title =titulo;
}@Override
protected void onPreExecute()
{
super.onPreExecute();
progress = new ProgressDialog(getActivity());
progress.setTitle("Synchronizing");
progress.setMessage("Removing '"+ title +"'
announcement please wait...");
progress.setIndeterminate(false);
progress.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
progress.show();
progress.setCancelable(false);
}@Override
protected String doInBackground(String... params) {
try {try {
connection = connectionclass(secured_Pref.getString("server",""), secured_Pref.getString("user",""), secured_Pref.getString("pass",""));
if (connection == null) {
Connection = false;
}
else
{
Connection = true;
PreparedStatement statement = connection.prepareStatement("DELETE FROM Announcements WHERE ID='"+this.ids.toString()+"' AND Title='"+this.title.toString()+"'");
long i =statement.executeUpdate();
try {
if (i>
0)
{
isSuccess = true;
} else {
isSuccess = false;
}
connection.close();
} catch (Exception x) {
Toast.makeText(getActivity(), "Error Occur.", Toast.LENGTH_SHORT).show();
}
}} catch (Exception e)
{
e.printStackTrace();
Toast.makeText(getActivity(), "Error Occur.", Toast.LENGTH_SHORT).show();
}
} catch (Exception ex) {
isSuccess = false;
}
return null;
}@Override
protected void onPostExecute(String r) {
super.onPostExecute(r);
if (Connection)
{
Toast.makeText(getActivity(),"Successfully Connected.",Toast.LENGTH_LONG).show();
}
else if(Connection==false)
{
Toast.makeText(getActivity(),"No Internet Connection.",Toast.LENGTH_LONG).show();
}
if (isSuccess)
{
Snackbar.make(getView(), "Announcement is Successfully Removed.", Snackbar.LENGTH_LONG).show();
//Refresh my fragment
FragmentTransaction refresh = getFragmentManager().beginTransaction();
refresh.detach(ViewAnnounce.this).attach(ViewAnnounce.this).commit();
}
else
{
Snackbar.make(getView(), "Oops! Error Occur.", Snackbar.LENGTH_LONG).show();
}
progress.dismiss();
}
}
ProGuard规则
-ignorewarnings
# Basic ProGuard rules for Firebase Android SDK 2.0.0+
-keep class com.firebase.** { *;
}
-keep class org.apache.** { *;
}
-keepnames class com.fasterxml.jackson.** { *;
}
-keepnames class javax.servlet.** { *;
}
-keepnames class org.ietf.jgss.** { *;
}
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
-renamesourcefileattribute SourceFile
-keep public class * extends android.app.Application
-optimizationpasses 5
-keepattributes *Annotation*,EnclosingMethod
在我的Gradle中
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
答案【通过在Android中实现Proguard,使用JDBC在Asynctask中崩溃】已经通过将此规则包含在我的程序中来修复
-dontshrink
推荐阅读
- 无法解析Android中的方法'execute()'
- Android Studio - 对象构造函数中的NetworkOnMainThreadException
- 无法将值传递给Android中的AsyncTask
- AsyncTask Android方法的技术差异
- Android AsyncTask问题(连接到Web服务)
- Android(Kotlin) - 如何等待异步任务完成()
- E / AndroidRuntime(致命异常:Android的AsyncTask#1 ERROR)
- Android AsyncTask无法运行
- AsyncTask在android中加载数据的次数非常不同