产生模糊库出一个Android库项目 [英] Producing an obfuscated library out of an Android Library Project

查看:140
本文介绍了产生模糊库出一个Android库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了使用的是Android库项目,也由我写的一个Android应用程序。我不得不释放该应用程序的源$ C ​​$ C,但我不希望分发库的来源。该库定义,除其他事项外,自定义视图,所以它包含XML布局和资源。我在想释放该库以二进制形式(一的.jar也许?),由主体工程引用。我想这个二进制库通过Proguard的进行模糊处理。这是可行的?怎么样?

I've written an Android application using an Android Library project, also written by me. I have to release the source code of the app, but I don't want to distribute the sources of the library. This library defines, among other things, custom views, so it includes XML layouts and resources. I was thinking of releasing this library in binary form (a .jar maybe?), to be referenced by the main project. I want this binary library to be obfuscated via Proguard. Is this feasible? How?

感谢。

推荐答案

正如刚才张逊,至少目前还没有任何方法来释放一个Android库项目作为一个罐子,也没有任何办法来混淆的项目除了Java源代码的。然而,有一种方法来混淆源$ C ​​$ C,虽然这不是正式支持。

As mentioned by Morrison Chang, there currently isn't any way to release an android library project as a jar, nor is there any way to obfuscate the project with the exception of the java source. However, there is a way to obfuscate the source code, although this is not officially supported.

所有你需要做的就是运行库中的蚂蚁干净发布命令。该模糊源被写入斌/ ProGuard的/ obfuscated.jar。只要把该jar文件中导出的库项目的libs目录,并删除src目录中的内容,和你的pretty的多少事。

All you need to do is run the "ant clean release" command in your library. The obfuscated source is written into "bin/proguard/obfuscated.jar". Just put that jar file in the libs directory of your exported library project, and delete the contents of the src directory, and your pretty much done.

有一个疑难杂症与上面的方法,但是。它不处理完全正确的资源。为了解决这个问题,你应该从你的obfuscated.jar副本去掉所有的资源类(R.class和R $ *类)。这反过来会要求您禁用混淆这些资源类。这可以通过加入以下的ProGuard-project.txt来完成:

There is one gotcha with the above approach, however. It doesn't handle resources quite right. To fix this, you should strip out all the resource classes (R.class and R$*.class) from your copy of obfuscated.jar. This in turn will require you to disable obfuscation for these resource classes. This can be done by adding the following to proguard-project.txt:

-keep public class **.R {
  public *;
}
-keep public class **.R$* {
  public *;
}

有关您参考,这里是我用它来建立一个经过模糊处理,sourceless的Andr​​oid库项目Ant目标:

For your reference, here is the ant target I use to build an obfuscated, sourceless android library project:

<?xml version="1.0" encoding="UTF-8"?>
<project name="library_rules" default="librelease">
  <target name="librelease" depends="release"
      description="Build a sourceless and obfuscated android library.">
    <property name="libname" value="myProject" />
    <property name="librelease.dir" location="bin/${libname}" />
    <delete file="${librelease.dir}"/>
    <mkdir dir="${librelease.dir}"/>
    <mkdir dir="${librelease.dir}/libs"/>
    <mkdir dir="${librelease.dir}/src"/>
    <copy todir="${librelease.dir}/res">
      <fileset dir="res"/>
    </copy>
    <copy file="AndroidManifest.xml" todir="${librelease.dir}" />
    <copy file="ant.properties" todir="${librelease.dir}" />
    <copy file="build.xml" todir="${librelease.dir}" />
    <copy file="project.properties" tofile="${librelease.dir}/project.properties" />
    <jar destfile="${librelease.dir}/libs/${libname}.jar">
      <zipfileset src="bin/proguard/obfuscated.jar" excludes="**/R.class,**/R$$*.class"/>
    </jar>
  </target>
</project>

在Android库项目出口将位于斌/ myProject的。这已经采用了Android SDK工具v20.0.3和V21测试。

The android library project to be exported will be located in bin/myProject. This has been tested using Android SDK tools v20.0.3 and v21.

这篇关于产生模糊库出一个Android库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆