简体   繁体   English

Proguard:找不到引用的类

[英]Proguard: can't find referenced class

There are a few questions around but no solution that works for me. 有几个问题,但没有解决方案适合我。 I thought it was suppose to be easy to use. 我认为这很容易使用。 I just get a console full of can't find referenced class 我只是得到一个完整的控制台can't find referenced class

This is my proguard-project.txt 这是我的proguard-project.txt

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars C:/Users/ME/android-sdks/platforms/android-10/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

and project.properties 和project.properties

#Proguard enabled
proguard.config=C:/Users/ME/android-sdks/tools/proguard/proguard-android.txt:proguard-project.txt

some of the classes with warnings are: 一些有警告的课程是:

org.apache.avalon.framework.logger.Logger
org.apache.log4j.Category
org.apache.log4j.Priority
org.apache.log4j.Logger
...
javax.servlet.ServletContextListener
javax.servlet.ServletContextEvent
org.w3c.dom.html.HTMLAnchorElement
org.w3c.dom.html.HTMLObjectElement
org.w3c.dom.html.HTMLTableSectionElement
org.w3c.dom.html.HTMLFrameSetElement
...
org.w3c.dom.events.DocumentEvent
org.w3c.dom.traversal.NodeFilter
...
org.w3c.dom.ranges.Range
org.w3c.dom.ranges.RangeException
...
org.w3c.dom.html.HTMLDocument

Add to your config: 添加到您的配置:

-libraryjars org.apache.jar // name of your jars.
-libraryjars org.w3c.jar

If it does not help add: 如果它没有帮助添加:

-dontwarn org.apache.** tag

or just ignore warnings (highly unrecommended since it could cause your app to crash at runtime over unsatisfied dependencies): 或者只是忽略警告(非常不推荐,因为它可能导致您的应用程序在运行时因未满足的依赖项而崩溃):

-ignorewarnings 

This doc will help you : http://proguard.sourceforge.net/manual/troubleshooting.html 本文档将为您提供帮助: http//proguard.sourceforge.net/manual/troubleshooting.html

If you have an error such as: 如果您有错误,例如:

Warning: com.package...: can't find referenced class com.secondpackage....Classname

Just add to your file proguard-android.txt: 只需添加到您的文件proguard-android.txt:

#if it is class:
-keep class com.package.*{ *; }
#or if it is interface:
-keep interface com.package.*{ *; }
#or if it is a class that extends from any other
-keep class * extends com.example.Model
#or if you know only and of className
-keep class **Starter { *; }
#or if you want to keep only fields of classes
-keepclassmembers class com.package.** {
   *;
}

Also if you dont want to see all of notes in log use: 此外,如果您不想在日志中看到所有注释:

-dontnote com.package.**

This file name is written in build Gradle 此文件名是在build Gradle中编写的

buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
        }
    } 

Or if you want to add many files for example use the following repo And for add all of files: 或者,如果您想要添加许多文件,例如使用以下repo并添加所有文件:

 buildTypes {
        release {
            minifyEnabled true

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            proguardFiles fileTree(include: ['*.pro'], dir: '../libraries').asList().toArray()
        }

libraries folder should be at D:\\workspace\\MyProject\\libraries libraries文件夹应位于D:\\workspace\\MyProject\\libraries

From what I can remember, it means you have referenced the Jar files in the wrong way. 从我记忆中来看,这意味着你以错误的方式引用了Jar文件。

Also, if your username (ME) contains spaces C:/Users/ME/android-sdks/tools/proguard/proguard-android.txt:proguard-project.txt Proguard will break in "funny" ways. 此外,如果您的用户名(ME)包含空格C:/Users/ME/android-sdks/tools/proguard/proguard-android.txt:proguard-project.txt Proguard将以“有趣”的方式打破。 Move android-sdk to C:\\android-sdk and save yourself headache. 将android-sdk移动到C:\\android-sdk并保存自己的头痛。

如果您正在使用库项目,那么应该将-libraryjars添加到库proguard配置中

In my case Android Studio froze while doing ProGuard on release build. 在我的情况下,Android Studio在发布版本上执行ProGuard时冻结。 I killed it. 我杀了它 And after the restart I started to see "can't find referenced class" warnings. 重启后我开始看到“找不到引用类”的警告。

solution: I closed Android Studio, deleted .gradle folder from my project folder, then deleted gradle global cache (%USER_HOME%.gradle/caches). 解决方案: 我关闭了Android Studio,从我的项目文件夹中删除了.gradle文件夹,然后删除了gradle全局缓存(%USER_HOME%.gradle / caches)。 After reopening the project, caches was rebuild and everything started to work again. 重新打开项目后,重建缓存,一切都开始重新运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android ProGuard:找不到引用的类 - Android ProGuard: can't find referenced class Proguard android找不到引用的类 - Proguard android can't find referenced class 在Proguard的类中找不到引用的方法 - can't find referenced method in class with Proguard Proguard警告:找不到引用的类scala。* - Proguard warnings: can't find referenced class scala.* 在Gradle中使用Proguard - 找不到引用的类java.lang.String - Using Proguard in Gradle - can't find referenced class java.lang.String Proguard找不到引用的com.google.ads.internal.state.AdState类 - Proguard can't find referenced class com.google.ads.internal.state.AdState Proguard:在库类java.lang.Throwable中找不到引用的方法&#39;void addSuppressed(java.lang.Throwable)&#39; - Proguard: can't find referenced method 'void addSuppressed(java.lang.Throwable)' in library class java.lang.Throwable 如何修复proguard警告&#39;找不到引用的方法&#39;用于类java.lang.Object的现有方法&#39;clone&#39;和&#39;finalize&#39; - how to fix proguard warning 'can't find referenced method' for existing methods 'clone' and 'finalize' of class java.lang.Object 警告:找不到引用的类 - Warning:can't find referenced class 使用proguard构建Android Studio版本:在程序中找不到引用的字段 - Android Studio release build with proguard: can't find referenced field in program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM