Ошибка сборки Proguard с библиотекой аннотаций Lombok

У Proguard возникают проблемы с библиотекой Lombok при использовании Gradle в Android Studio для компиляции библиотеки. Я нашел некоторую информацию о конфигурации, чтобы исправить масляный нож, другую библиотеку аннотаций, которую мы используем.

-keepattributes *Annotation*
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

Кто-нибудь знает, какие флаги нужно добавить, чтобы сделать Ломбок счастливым.

Конфигурационный файл Proguard

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags.  Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik.  The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.)  Make sure you
# test thoroughly if you go this route.
#-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/allocation/variable
-dontobfuscate
#-optimizationpasses 5
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

#-dontusemixedcaseclassnames
#-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

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

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

Несколько ошибок, которые я вижу ...

Warning:lombok.core.Agent$NetbeansPatcherInfo$1: can't find superclass or interface java.lang.instrument.ClassFileTransformer
Warning:lombok.core.AnnotationProcessor: can't find superclass or interface javax.annotation.processing.AbstractProcessor
Warning:lombok.delombok.DocCommentIntegrator$CommentAttacher_8$1: can't find superclass or interface com.sun.tools.javac.parser.Tokens$Comment
Warning:lombok.delombok.PrettyCommentsPrinter: can't find superclass or interface com.sun.tools.javac.tree.JCTree$Visitor
Warning:lombok.delombok.PrettyCommentsPrinter$1UsedVisitor: can't find superclass or interface com.sun.tools.javac.tree.TreeScanner
Warning:lombok.delombok.ant.DelombokTask: can't find superclass or interface org.apache.tools.ant.Task
Warning:lombok.eclipse.EclipseAstProblemView$LombokProblem: can't find superclass or interface org.eclipse.jdt.internal.compiler.problem.DefaultProblem
Warning:lombok.eclipse.agent.ExtensionMethodCompletionProposal: can't find superclass or interface org.eclipse.jdt.internal.codeassist.InternalCompletionProposal
Warning:lombok.eclipse.handlers.SetGeneratedByVisitor: can't find superclass or interface org.eclipse.jdt.internal.compiler.ASTVisitor
Warning:lombok.installer.InstallerGUI$12: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$13: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$2: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$3: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$4: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$6: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$6$2: can't find superclass or interface javax.swing.filechooser.FileFilter
Warning:lombok.installer.InstallerGUI$7: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$8: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$9: can't find superclass or interface java.awt.event.ActionListener
...
Warning: there were 10560 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 128 instances of library classes depending on program classes.
         You must avoid such dependencies, since the program classes will
         be processed, while the library classes will remain unchanged.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
Warning: there were 103 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
:just10:proguardGooglePhoneDevDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':just10:proguardGooglePhoneDevDebug'.
> java.io.IOException: Please correct the above warnings first.

person Cory Roy    schedule 14.08.2014    source источник
comment
Если ваш проект связан с классами java.awt или javax.swing, это очень подозрительно - их нет на Android.   -  person Scott Barta    schedule 14.08.2014
comment
@ScottBarta Это просто установщик Lombok Eclipse, встроенный в jar.   -  person copolii    schedule 14.08.2014
comment
Lombok работает с исходным кодом, а AFAIK Proguard работает только с файлами JAR. Lombok не имеет зависимостей во время выполнения; он вам не нужен после компиляции, поэтому Proguard не нужен и вообще не должен видеть lombok.jar.   -  person maaartinus    schedule 14.08.2014


Ответы (2)


Если вы используете директиву compile в файле сборки gradle, измените ее на provided

В Eclipse есть аналогичное решение, в котором вы можете разбить jar на lombok-api.jar, который вы включаете в свои библиотеки. Я попытался найти инструкции, но не могу найти страницу, объясняющую, как это сделать (это было больше года назад, поэтому, возможно, это изменилось).

Спасибо Роэлу (см. Ниже), вот командная строка для использования: java -jar lombok.jar publicApi

person copolii    schedule 14.08.2014
comment
Вы можете использовать java -jar lombok.jar publicApi для создания этой банки. - person Roel Spilker; 18.08.2014
comment
Это тот самый. Спасибо. - person copolii; 18.08.2014

Я добавил несколько флагов для подавления предупреждений для включенных библиотек в свой проект, и это помогло.

-dontwarn javax.**
-dontwarn lombok.**
-dontwarn org.apache.**
-dontwarn com.squareup.**
-dontwarn com.sun.**
-dontwarn **retrofit**
person Cory Roy    schedule 14.08.2014
comment
Куда вы положили эти заявления? - person IgorGanapolsky; 04.02.2015
comment
Игорь, я положил файл proguard-config.txt в корневой каталог вашего приложения для Android. - person Cory Roy; 04.02.2015
comment
Но это применимо только для сборок выпуска. - person IgorGanapolsky; 04.02.2015
comment
Его будут использовать любые типы сборки, для которых minifyEnabled установлено значение true. - person Cory Roy; 05.02.2015