2016-08-05 8 views
1

proguardでJAXBコードを難読化したい。これは、完全なJavaクラスのコードです:proguardでJAXBコードを難読化する際のIllegalAnnotationsException

import java.util.List; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlAttribute; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlElementWrapper; 
import javax.xml.bind.annotation.XmlType; 

@XmlType(propOrder = 
{ 
    "setting", "subsystems" 
}) 
@XmlAccessorType(XmlAccessType.FIELD) 
public class ProfileImpl implements Profile 
{ 
    @XmlAttribute 
    private String name; 
    @XmlAttribute 
    private final String version; 
    @XmlElementWrapper(name = "subsystems") 
    @XmlElement(name = "subsystem") 
    private List<SubsystemImpl> subsystems; 
    private SettingImpl setting; 

    public ProfileImpl() 
    { 
     this.version = "1.0"; 
     this.name = "default"; 
    } 

    public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version) 
    { 
     this.name = name; 
     this.setting = setting; 
     this.version = version; 
     this.subsystems = subsystems; 
    } 

    public String getName() 
    { 
     return name; 
    } 

    public void setName(String name) 
    { 
     this.name = name; 
    } 

    public List<SubsystemImpl> getSubsystems() 
    { 
     return subsystems; 
    } 

    public void setSubsystems(List<SubsystemImpl> subsystems) 
    { 
     this.subsystems = subsystems; 
    } 

    public SettingImpl getSetting() 
    { 
     return setting; 
    } 

    public void setSetting(SettingImpl setting) 
    { 
     this.setting = setting; 
    } 
} 

しかし、私は、コードを実行したときに私が取得:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions 
Property c is present but not specified in @XmlType.propOrder 
     this problem is related to the following location: 
       at private java.util.List org.settings.loader.osgi.impl.jaxb.ProfileImpl.c 
       at org.settings.loader.osgi.impl.jaxb.ProfileImpl 
       at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b 
       at org.settings.loader.osgi.impl.jaxb.f 
Property d is present but not specified in @XmlType.propOrder 
     this problem is related to the following location: 
       at private org.settings.loader.osgi.impl.jaxb.d org.settings.loader.osgi.impl.jaxb.ProfileImpl.d 
       at org.settings.loader.osgi.impl.jaxb.ProfileImpl 
       at private java.util.List org.settings.loader.osgi.impl.jaxb.f.b 
       at org.settings.loader.osgi.impl.jaxb.f 

私は問題を解決できますか?

私はクラスの難読化をスキップするために、このProGuardの設定を試してみました:

<option>-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl{public *; private *;} -keepattributes Exceptions, *Annotation*, InnerClasses, Signature, SourceFile, EnclosingMethod -dontshrink -dontoptimize -keepparameternames</option> 
+0

'ProfileImpl'全体を追加できますか? – Xstian

+0

投稿が更新されました –

+0

'SettingImpl setting'で' XmlElement'アノテーションが見つかりませんでしたか? –

答えて

1

として定義すると、あまりにも小道具ために、「名前」と「バージョン」を追加してください。注釈は引数

-keep public class javax.xml.bind.** 
-keep public class org.settings.loader.osgi.impl.jaxb.ProfileImpl implements org.settings.loader.osgi.impl.jaxb.Profile 
-keepattributes *Annotation* 

http://proguard.sourceforge.net/manual/examples.html#annotations

に以下を追加しよう

更新

私はあなたのコードを以下のように少し変更しました。 この変更後、コードに続くパラメータを含めて変更があるかどうかを確認してください。

public class ProfileImpl implements Profile 
{ 
    private String name; 
    private final String version; 
    private List<SubsystemImpl> subsystems; 
    private SettingImpl setting; 

    public ProfileImpl(){ 
     this.version = "1.0"; 
     this.name = "default"; 
    } 

    public ProfileImpl(String name, SettingImpl setting, List<SubsystemImpl> subsystems, String version){ 
     this.name = name; 
     this.setting = setting; 
     this.version = version; 
     this.subsystems = subsystems; 
    } 

    @XmlAttribute(name = "name") 
    public String getName(){ 
     return name; 
    } 

    public void setName(String name){ 
     this.name = name; 
    } 

    @XmlAttribute(name = "version") 
    public String getVersion(){ 
     return version; 
    } 

    public void setVersion(String version){ 
     this.version = version; 
    } 

    @XmlElementWrapper(name = "subsystems") 
    @XmlElement(name = "subsystem") 
    public List<SubsystemImpl> getSubsystems(){ 
     return subsystems; 
    } 

    public void setSubsystems(List<SubsystemImpl> subsystems){ 
     this.subsystems = subsystems; 
    } 

    public SettingImpl getSetting(){ 
     return setting; 
    } 

    public void setSetting(SettingImpl setting){ 
     this.setting = setting; 
    } 
} 
+0

私はすでに結果なしでこれをテストしました。更新された投稿をご覧ください。 –

+0

@PeterPenzov更新があれば教えてください –

+0

私はこのjava.lang.NullPointerExceptionを受け取ります org.settings.loader.osgi.impl.jaxb.f.a(不明なソース) –

0

アクセスタイプがプロセスにProGuardのためのフィールド

+0

Cnaあなたはいくつかの詳細な情報を何を意味しますか? –

+0

@ peter-penzov 'private SettingImpl setting'は、難読化処理時に名前が変更されているので、新しい名前は' d'のようなものです。一方、 'propOrder'に' setting'を指定し、jaxbがそれを見つけることができませんでした(実際にはそのフィールドはもはや存在しません)。 @XmlAttribute(name = "...") ' – vsminkov

+0

のようなアノテーションの名前属性を設定します。はい、これらのフィールドの名前を変更しないようにProguardを設定する方法はありますか? –

関連する問題