【问题标题】:How to prevent proguard to shrink module library ? JAR如何防止proguard收缩模块库?罐
【发布时间】:2019-09-24 04:20:44
【问题描述】:

我有我导入到我的项目中的 fishwjy 视频压缩器库,当我在调试模式下运行代码压缩视频时一切正常,但是当我在发布模式下构建 apk 后运行视频压缩时出现错误,这个问题来自后卫?我该如何解决这个问题?,以及如何让模块远离 proguard?

我的 build.gradle

buildTypes {
        release {
            lintOptions {
                disable 'MissingTranslation'
                checkReleaseBuilds false
                abortOnError false
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

我的保护规则

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Android/AndroidSdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.woxthebox.draglistview.** { *; }
-keep class com.vincent.videocompressor.** { *; }
-keepclassmembers com.vincent.videocompressor.** { *; }
-keep class videocompressor.**
-keepclassmembers videocompressor.**

-keep public class com.vincent.videocompressor.** {
  public protected *;
}
-keep public class videocompressor.** {
  public protected *;
}

这是错误,我进入了发布模式

java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:354)
    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:245)
    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:764)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/aspectj/runtime/reflect/Factory;
    at com.coremedia.iso.boxes.FileTypeBox.ajc$preClinit(FileTypeBox.java:1)
    at com.coremedia.iso.boxes.FileTypeBox.<clinit>(FileTypeBox.java:1)
    at com.vincent.videocompressor.MP4Builder.createFileTypeBox(MP4Builder.java:155)
    at com.vincent.videocompressor.MP4Builder.createMovie(MP4Builder.java:62)
    at com.vincent.videocompressor.VideoController.convertVideo(VideoController.java:341)
    at com.vincent.videocompressor.VideoCompress$VideoCompressTask.doInBackground(VideoCompress.java:51)
    at com.vincent.videocompressor.VideoCompress$VideoCompressTask.doInBackground(VideoCompress.java:32)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 4 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.aspectj.runtime.reflect.Factory" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.myapps.myapps-rN2AAoto-QpoZhVaUg_EFQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapps.myapps-rN2AAoto-QpoZhVaUg_EFQ==/lib/arm64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 13 more

【问题讨论】:

标签: android module proguard android-library video-compression


【解决方案1】:

使用 -dontshrink

来自proguardmanual

-dontshrink 指定不收缩输入。默认情况下,ProGuard 会缩小代码:它会删除所有未使用的类和类成员。它 只保留由各种 -keep 选项列出的那些,以及那些 他们直接或间接依赖的东西。它还应用了一个 在每个优化步骤之后缩小步骤,因为一些优化 可能会打开删除更多类和类成员的可能性。

【讨论】:

    猜你喜欢
    • 2015-05-23
    • 2021-10-15
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多