android 工程eclipse打包so和jar包混淆

时间:2021-12-11 09:12:28

android 工程eclipse ndk生成的so文件,java文件打包成jar包可以直接调用so库。类似百度地图的方式。

1、使用ndk将jni文件编译成so文件,外层调用的java文件右键->export->java->jar file,打包成jar包,此时jar包没混淆很不安全,使用android tools->proguard->bin下面的proguardgui.bat工具可以将jar包混淆。具体的使用方法百度。
我的混淆文件如下:

-injars 'C:\Users\Administrator\Desktop\AdasInterface.jar'
-outjars 'C:\Users\Administrator\Desktop\adas.jar'

-libraryjars 'D:\soft\android_environment\adt-bundle-windows-x86_64-20140321\sdk\platforms\android-19\android.jar'

-target 1.6
-useuniqueclassmembernames
-renamesourcefileattribute SourceFile
-adaptresourcefilenames **.properties
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF
-verbose


-keep public class com.google.vending.licensing.ILicensingService

-keep public class com.android.vending.licensing.ILicensingService

-keep public class com.adasplus.adas.AdasInterface {

<fields>;
<methods>;
}

-keep public class com.adasplus.data.AdasConfig {
<fields>;
<methods>;
}

-keep public class com.adasplus.data.CarInfo {
<fields>;
<methods>;
}

-keep public class com.adasplus.data.FcwInfo {
<fields>;
<methods>;
}

-keep public class com.adasplus.data.LaneInfo {
<fields>;
<methods>;
}

-keep public class com.adasplus.data.LdwInfo {
<fields>;
<methods>;
}

-keep public class com.adasplus.data.RectInt {
<fields>;
<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);
}

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

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

# Keep - Library. Keep all public and protected classes, fields, and methods.
#-keep public class * {
# public protected <fields>;
# public protected <methods>;
#}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
native <methods>;
}

2、此时将so库和jar包放在其他工程的libs下面,so文件放在ameabi等目录下,即可正常使用。

3、利用eclipse自动生成文档,首先需要对自己的代码进行注释,因为javadoc工具是根据注释格式来生成文档的,生成文档的快捷方式为Alt+Shift+J,具体注释的格式可以自己设定window->preference->Java->Code Style->Code Templates->Comments。

<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
* &lt;p&gt;Title: ${enclosing_method}&lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* ${tags}
*/

</template><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
* &lt;p&gt;Title: &lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* ${tags}
*/
</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
* &lt;p&gt;Title: ${type_name}&lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* &lt;p&gt;Company: ADASIM&lt;/p&gt;
* @author wangmm0220@gmail.com
* @date ${date}
*/

</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/**
* &lt;p&gt;Title: ${file_name}&lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* &lt;p&gt;Copyright: Copyright (c) 2016&lt;/p&gt;
* &lt;p&gt;Company: ADASIM&lt;/p&gt;
* @author wangmm0220@gmail.com
* @date ${date}
* @version 1.0
*/
</template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/*(non-Javadoc)
* &lt;p&gt;Title: ${enclosing_method}&lt;/p&gt;
* &lt;p&gt;Description: &lt;/p&gt;
* ${tags}
* ${see_to_overridden}
*/

</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
* @return the ${bare_field_name}
*/
</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**${field}*/</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
* @param ${param} the ${bare_field_name} to set
*/
</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
* ${tags}
* ${see_to_target}
*/
</template></templates>

选中需要生成文档的java文件,右键->export->java->javadoc,可在下面的选项中选择对于那些成员生成文档。生成的文档将在doc目录下。