【问题标题】:Proguard keep option to handle OSGi declarative serviceProguard 保留选项来处理 OSGi 声明式服务
【发布时间】:2021-03-08 05:04:11
【问题描述】:

什么是用于 OSGi 声明式服务与 Proguard 混淆的 keep 选项

参考下面的例子,我需要保留DS相关的功能,不用Proguard删除它,因为它找不到参考

@Component
public class RandomApp {

    private RandomGenApi randomGenApi;

    @Reference
    public void setRandomGenService(RandomGenApi randomGenApi) {
        this.randomGenApi = randomGenApi;
    }
      
    
    @Activate
    void startRandomApp() {
        System.out.println("Startig RandomApp...");          

    }

【问题讨论】:

    标签: osgi proguard osgi-bundle


    【解决方案1】:

    我可以通过将 OSGi 服务定义为入口点来实现这一点。 这是要定义的保留选项

    #Keep annotations.
    -keepattributes *Annotation*
    
    #Keep all Component classes
    -keep @org.osgi.service.component.annotations.Component class *
    
    #Kepp all Component classes member functions with OSGi specific annotations
    -keepclassmembers @org.osgi.service.component.annotations.Component class * {
       #Keep all methods with annotatios Reference.
       @org.osgi.service.component.annotations.Reference *;
       #Keep all methods with annotatios Activate.
       @org.osgi.service.component.annotations.Activate *;   
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 2013-10-09
      • 2018-05-20
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多