使用minifyenable true构建我的应用程序时,出现以下错误提示。奇怪的是,当我使用minifyenable false进行编译时,应用程序正常运行。该应用程序使用Tesseract来扫描文档。
我想念什么?
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:304)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
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:818)
Caused by: java.lang.NoSuchFieldError: no "J" field "mNativeData" in class "Lcom/googlecode/tesseract/android/TessBaseAPI;" or its superclasses
at com.googlecode.tesseract.android.TessBaseAPI.nativeClassInit(Native Method)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(Unknown Source)
at br.com.cfb.doarnf.el.a(Unknown Source)
at br.com.cfb.doarnf.a.a(Unknown Source)
at br.com.cfb.doarnf.a.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
build.gradle(模块:应用程序)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "br.com.cfb.doarnf"
minSdkVersion 17
targetSdkVersion 23
versionCode 5
versionName "2.1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':tess-two')
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.parceler:parceler:1.0.1'
compile 'org.parceler:parceler-api:1.0.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.github.orangegangsters:swipy:1.2.0@aar'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.zxing:core:3.2.1'
}
build.gradle(模块:tess-two)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
}
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
}
dependencies {
}
最佳答案
我找到了解决方法。只是避免了ProGuard处理tess-two库,请遵循以下步骤:
将ConsumerProguardFiles添加到build.gradle(模块:tess-two)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 23
consumerProguardFiles 'proguard-tess-two-rules.txt'
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
}
dependencies {
}
proguard-tess-two-rules.txt文件
# Add tess-two specific ProGuard rules here.
-dontoptimize
-dontobfuscate
-dontpreverify
-dontshrink
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontusemixedcaseclassnames
-dontnote
我希望它可以帮助某人。