ProGuard с Maven-Android-плагином

1

Я пытаюсь упаковать свой проект в APK, а затем запутать его с помощью ProGuard.

Вот мой pom:

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.skayred</groupId>
    <artifactId>skayred</artifactId>
    <version>1.26</version>
    <packaging>apk</packaging>
    <name>skayred</name>

<properties>
    <environment>development</environment>
</properties>

<dependencies>

    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>2.2_r3</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.android.maps</groupId>
        <artifactId>maps</artifactId>
        <version>8_r2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client</artifactId>
        <version>1.6.0-beta</version>
        <exclusions>

            <exclusion>
                <groupId>xpp3</groupId>
                <artifactId>xpp3</artifactId>
            </exclusion>

            <exclusion>
                <groupId>com.google.protobuf</groupId>
                <artifactId>protobuf-java</artifactId>
            </exclusion>

            <exclusion>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-asl</artifactId>
            </exclusion>

            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>

            <exclusion>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
            </exclusion>

            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>

            <exclusion>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
            </exclusion>

            <exclusion>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
            </exclusion>

            <exclusion>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>jsr305</artifactId>
            </exclusion>

        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-extensions-android2</artifactId>
        <version>1.6.0-beta</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>10.0.1</version>

        <exclusions>
            <exclusion>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>jsr305</artifactId>
            </exclusion>
        </exclusions>

    </dependency>

    <dependency>
        <groupId>com.skyhookwireless.wps</groupId>
        <artifactId>skyhookwireless-wps</artifactId>
        <version>4.2.0.14</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.bugsense.trace</groupId>
        <artifactId>bugsense-trace</artifactId>
        <version>1.1.2</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jarsigner-plugin</artifactId>
        <version>1.2</version>

        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>

    </dependency>

</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>

    <resources>
        <!-- a pair definition for resource filtering of xml files only (not binary files since they get mangled -->
        <resource>
            <directory>${project.basedir}/res</directory>
            <filtering>true</filtering>
            <targetPath>${project.build.directory}/filtered-res</targetPath>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>${project.basedir}/res</directory>
            <filtering>false</filtering>
            <targetPath>${project.build.directory}/filtered-res</targetPath>
            <excludes>
                <exclude>**/*.xml</exclude>
            </excludes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.0.0</version>
            <extensions>true</extensions>
            <configuration>
                <resourceDirectory>${project.build.directory}/filtered-res</resourceDirectory>
                <manifest>
                    <debuggable>true</debuggable>
                </manifest>
                <dex>
                    <jvmArguments>
                        <jvmArgument>-Xms256m</jvmArgument>
                        <jvmArgument>-Xmx512m</jvmArgument>
                    </jvmArguments>
                </dex>
                <sdk>
                    <platform>8</platform>
                </sdk>
            </configuration>
            <executions>
                <execution>
                    <id>manifestUpdate</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>manifest-update</goal>
                    </goals>
                </execution>
                <execution>
                    <id>alignApk</id>
                    <phase>package</phase>
                    <goals>
                        <goal>zipalign</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

<profiles>
    <profile>
        <id>development</id>
        <!-- using this since activeByDefault does not work well with multiple profiles -->
        <activation>
            <property>
                <name>environment</name>
                <value>!production</value>
            </property>
        </activation>
        <properties>
            <deployment.host>http://192.168.192.15:5000</deployment.host>
        </properties>
    </profile>
    <profile>
        <id>production</id>

        <properties>
            <deployment.host>https://somehost.com</deployment.host>
        </properties>
    </profile>
    <profile>
        <id>release</id>
        <properties>
            <deployment.host>https://somehost.com</deployment.host>
        </properties>
        <!-- via this activation the profile is automatically used when the release is done with the maven release
        plugin -->
        <activation>
            <property>
                <name>performRelease</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jarsigner-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>signing</id>
                            <goals>
                                <goal>sign</goal>
                                <goal>verify</goal>
                            </goals>
                            <phase>package</phase>
                            <inherited>true</inherited>
                            <configuration>
                                <removeExistingSignatures>true</removeExistingSignatures>
                                <archiveDirectory/>
                                <includes>
                                    <include>${project.build.directory}/${project.artifactId}.apk</include>
                                </includes>
                                <keystore>${sign.keystore}</keystore>
                                <alias>${sign.alias}</alias>
                                <storepass>${sign.storepass}</storepass>
                                <keypass>${sign.keypass}</keypass>
                                <verbose>true</verbose>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- the signed apk then needs to be zipaligned and we activate proguard and we run the manifest
                update -->
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <inherited>true</inherited>
                    <configuration>
                        <sign>
                            <debug>false</debug>
                        </sign>
                        <zipalign>
                            <verbose>true</verbose>
                            <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
                            <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk
                            </outputApk>
                        </zipalign>
                        <manifest>
                            <debuggable>false</debuggable>
                            <versionCodeAutoIncrement>true</versionCodeAutoIncrement>
                        </manifest>
                        <proguard>
                            <skip>false</skip>
                        </proguard>
                    </configuration>
                    <executions>
                        <execution>
                            <id>manifestUpdate</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>manifest-update</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>alignApk</id>
                            <phase>package</phase>
                            <goals>
                                <goal>zipalign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.directory}/${project.artifactId}-signed-aligned.apk</file>
                                <type>apk</type>
                                <classifier>signed-aligned</classifier>
                            </artifact>
                            <artifact>
                                <file>${project.build.directory}/proguard/mapping.txt</file>
                                <type>map</type>
                                <classifier>release</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>
                    <executions>
                        <execution>
                            <id>attach-signed-aligned</id>
                            <phase>package</phase>
                            <goals>
                                <goal>attach-artifact</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

proguard.cfg:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-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.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

Но когда я пытаюсь запустить mvn3 clean install -Prelease -X, у меня есть ошибка и команда loooong. Когда я пытаюсь запустить эту команду, у меня есть:

Warning: com.google.common.collect.AbstractBiMap: can't find referenced class javax.annotation.Nullable
Warning: com.google.common.collect.AbstractBiMap: can't find referenced class javax.annotation.Nullable
Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Note: there were 1 references to unknown classes.
  You should check your configuration for typos.
Warning: there were 1277 unresolved references to classes or interfaces.
     You may need to specify additional library jars (using '-libraryjars'),
     or perhaps the '-dontskipnonpubliclibraryclasses' option.
Warning: there were 6 unresolved references to program class members.
     Your input classes appear to be inconsistent.
     You may need to recompile them and try again.
     Alternatively, you may have to specify the options 
     '-dontskipnonpubliclibraryclasses' and/or
     '-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:308)
at proguard.ProGuard.initialize(ProGuard.java:210)
at proguard.ProGuard.execute(ProGuard.java:85)
at proguard.ProGuard.main(ProGuard.java:499)

И много предупреждений о ссылках ранее. Что я делаю неправильно?

  • 0
    Как вы интегрируете Google LVL в свой проект, как проект библиотеки или копировать исходный код?
  • 0
    Что такое лвл? оо
Показать ещё 3 комментария
Теги:
maven
proguard

1 ответ

3
Лучший ответ

Предупреждения говорят, что многие классы, которые вы обрабатываете, относятся к классам, которые отсутствуют во входных баночках или библиотечных баночках:

Это обычная проблема в Android, где вы обрабатываете сторонние библиотеки, которые зависят от других недостающих библиотек (но на самом деле их не используют на практике). Некоторые вопросы и ответы, касающиеся Android:

(Безвредная) заметка гласит, что ваш proguard.cfg ссылается на com.android.vending.licensing.ILicensingService, но этот класс отсутствует в вашем коде. Вы можете удалить строку из конфигурации.

  • 0
    Заметка о LicensingService отклонена, но исключение и предупреждения остались.
  • 0
    Я применил все -dontwarn и предупреждение о resolvin тоже исчезает

Ещё вопросы

Сообщество Overcoder
Наверх
Меню