gpt4 book ai didi

android - 外部库在发布 apk android 中不起作用

转载 作者:行者123 更新时间:2023-11-30 04:54:31 25 4
gpt4 key购买 nike

我正在将我的 android 项目 eclipse 迁移到 android studio。在项目中,我使用了 JTDS 库来连接数据库。问题是它在调试 Apk 时工作正常,但是当我创建发布 Apk 时,出现以下错误。

 Caused by: java.lang.NoClassDefFoundError: net.sourceforge.jtds.jdbc.BlobImpl

所以经过一些 RND,我猜在发布的 Apk 中有一个问题,无法在 Apk 中包含 jtds jar 文件。请给我建议。

这里是一些代码:

构建.gradle

apply plugin: 'com.android.application'

android {
signingConfigs {
releaseConfig {
storeFile file('F:\\codebase\\android')
storePassword var3
keyAlias = var4
keyPassword var5
}
}
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
applicationId "com.app"
minSdkVersion 16
targetSdkVersion 28
}

buildTypes {
release {
debuggable true
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseConfig
}
}

lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:28.0.0'
implementation files('libs/sun.misc.BASE64Decoder.jar')
implementation files('libs\\jtds-1.2.5.jar')
android {
useLibrary 'org.apache.http.legacy'
}
}

此功能在发布的 Apk 中不起作用

  public static Statement connectionOpen() {
try {
// Establish the connection.
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionUrl);
stmt = con.createStatement();
} catch (Exception e) {
exceptionData.setExceptionData(e.getMessage(), "connectionOpen");
e.printStackTrace();
}
return stmt;
}

Logcat 错误

2019-12-24 15:11:45.524 7770-7890/com.dm.rcl_app E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.m.app, PID: 7770
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:399)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.NoClassDefFoundError: net.sourceforge.jtds.jdbc.BlobImpl
at c.a.a.a.l0.a(:75)
at c.a.a.a.l0.<clinit>(:87)
at c.a.a.a.l0.a(:117)
at c.a.a.a.h.a(:1500)
at c.a.a.a.n0.M(:3219)
at c.a.a.a.n0.w(:2282)
at c.a.a.a.n0.a(:610)
at c.a.a.a.h.<init>(:345)
at c.a.a.a.m.connect(:187)
at java.sql.DriverManager.getConnection(DriverManager.java:580)
at java.sql.DriverManager.getConnection(DriverManager.java:236)
at b.a.d.g.b(:41)
at com.dm._app.Syncronization$d.a(:225)
at com.dm._app.Syncronization$d.doInBackground(:192)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:919) 
2019-12-24 15:11:45.576 4844-4923/? E/InputDispatcher: channel 'a694dba processing Data (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-12-24 15:11:45.576 4844-4923/? E/InputDispatcher: channel 'f996a44 com.dm.rcl_app/com.dm.Syncronization (server)' ~ Channel is unrecoverably broken and will be disposed!

最佳答案

更新在 proguard-rules.pro 中添加这一行

-keep net.sourceforge.jtds.**

结束更新

如果只发生在release模式,说明你没有正确配置proguard规则。看看this .

在 proguard-rules.pro 中添加这一行应该可以解决问题

-dontwarn net.sourceforge.jtds.**

关于android - 外部库在发布 apk android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59466950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com