4

I'm getting the error

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'. Job failed, see logs for details

I get a lot of warnings like

Warning:es.usc.citius.hipster.util.examples.maze.MazeSearch$Result: can't find referenced class java.awt.Point

that looks weird for me because in my proguard-rules I added this rule

-keep public class es.usc.citius.hipster.** { *; }

[EDITED] I'm also getting warnings like

Warning:com.mypackage.android.dagger.modules.AppModule_ProvideAccelerometerSensorFactory: can't find superclass or interface dagger.internal.Factory

I added dagger rules

-dontwarn dagger.internal.codegen.**
-keepclassmembers,allowobfuscation class * {
    @javax.inject.* *;
    @dagger.* *;
    <init>();
}

-keep class dagger.* { *; }
-keep class javax.inject.* { *; }
-keep class * extends dagger.internal.Binding
-keep class * extends dagger.internal.ModuleAdapter
-keep class * extends dagger.internal.StaticInjection

and rule for keeping my package

-keep public class com.mypackage.android.** { *; }

After the answer about ignoring warnings, I added this rule

-dontwarn com.mypackage.android.**

And proguard doesn't fail now. However, I'm not sure if that the best practice and what can be broken after ignoring these warnings?

jakub
  • 3,576
  • 3
  • 29
  • 55
  • Possible duplicate of [proguard hell - can't find referenced class](https://stackoverflow.com/questions/6974231/proguard-hell-cant-find-referenced-class) – user1643723 Jul 17 '17 at 09:49

2 Answers2

2

The library class es.usc.citius.hipster.util.examples.maze.MazeSearch references a package java.awt.Point which is part of JDK but not Android JDK, which does not contain this package. You just cannot use it in Android Environment.

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • Thank you! I edited, my question. Will be grateful for the answer and clarification of my doubts. – jakub May 23 '17 at 09:48
2

Updated

And proguard doesn't fail now. However, I'm not sure if that the best practice and what can be broken after ignoring these warnings?

Android has its own graphics libraries (e.g. android.graphics), use it instead of the Java AWT classes.

Here's a pretty useful comment from java.awt.Toolkit:

WARNING: This is a temporary workaround for a problem in the way the AWT loads native libraries. A number of classes in the AWT package have a native method, initIDs(), which initializes the JNI field and method ids used in the native portion of their implementation. Since the use and storage of these ids is done by the implementation libraries, the implementation of these method is provided by the particular AWT implementations (for example, "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The problem is that this means that the native libraries must be loaded by the java.* classes, which do not necessarily know the names of the libraries to load. A better way of doing this would be to provide a separate library which defines java.awt.* initIDs, and exports the relevant symbols out to the implementation libraries. For now, we know it's done by the implementation, and we assume that the name of the library is "awt". -br. If you change loadLibraries(), please add the change to java.awt.image.ColorModel.loadLibraries(). Unfortunately, classes can be loaded in java.awt.image that depend on libawt and there is no way to call Toolkit.loadLibraries() directly. -hung

Original

class java.awt.Point

java.awt.* classes are not part of the Android runtime. The best solution would be to remove the classes that reference them.

Simplest solution would be just suppress the warnings:

-dontwarn java.awt.**
Stas Lelyuk
  • 538
  • 6
  • 19
  • Thank you! I edited, my question. Will be grateful for the answer and clarification of my doubts. – jakub May 23 '17 at 09:49