android sdk开发

后续再来完善
先留个记录:
Android Studio使用AIDL技术进行SDK开发
Android Studio中用gradle打包带AIDL文件的jar文件
使用Android Studio打包生成Jar包的方法(亲测可用)

如果SDK中不涉及res资源文件的话,可以选择打包成jar:
首先找到编译生成的class文件所在的目录
build/intermediates/javac/release/classes/
在这里插入图片描述
在这里插入图片描述
然后在SDK所在的module的build.gradle的最外层,添加如下代码:

//下面的aidl_java_make_jar只是一个方法名称可以随意取名,但是必须得和下面的aidl_java_make_jar.dependsOn(build)这里面的aidl_java_make_jar方法名称一致
task aidl_java_make_jar(type: Jar) {

    from "build/intermediates/javac/release/classes/"//核心,将java生成的.class 文件编译成Jar包,表示打包的文件目录

    destinationDir = file('build/libs')//指定jar生成的目录

//    exclude('/android')//用来过滤掉build/intermediates/classes/release/android这个文件夹(这个文件夹打包进去的话使用jar包的时候会出错)

    archiveName 'SDK.jar'//指定生成的jar的名字

   }

aidl_java_make_jar.dependsOn(build)//dependsOn  表示class_jar这个Task依赖于build,B.dependsOn A, 这意味着,只要我执行task B,task A都会先执行

然后,sync一下,等到sync完成后,点击andorid studio IDE右侧的Gradle,选择sdk module下的Tasks-other,找到刚刚命名的方法,双击。
在这里插入图片描述
然后就可以在build/libs 下找到对应的jar啦

混淆Jar

在SDK所在的module的build.gradle的最外层,继续添加如下代码

task aidl_make_proguard_jar(type: proguard.gradle.ProGuardTask) {
    // 未混淆的jar路径
    injars 'build/libs/'+'SDK.jar'//上一步打包生成的jar的名字

    // 混淆后的jar输出路径
    outjars 'build/libs/release_'+'SDK.jar'//混淆后输出的jar的名字

    // 混淆协议
    configuration 'proguard-rules.pro'
}
aidl_make_proguard_jar.dependsOn(build)

然后,sync一下,等到sync完成后,点击andorid studio IDE右侧的Gradle,选择sdk module下的Tasks-other,找到刚刚命名的方法,双击执行即可生成混淆后的jar。

proguard-rules.pro:

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile


# 表示混淆时不使用大小写混合类名
-dontusemixedcaseclassnames
# 表示不跳过library中的非public的类
-dontskipnonpubliclibraryclasses
# 打印混淆的详细信息
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
# 表示不进行校验,这个校验作用 在java平台上的
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
#保留@Keep注解
-keep,allowobfuscation interface androidx.annotation.Keep
-keep @androidx.annotation.Keep class *

-dontwarn androidx.annotation.Keep

-keepclassmembers class * {
@androidx.annotation.Keep *;
}
#忽略警告
-ignorewarnings
#保留内部类,异常,签名
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
#保留方法参数名
-keepparameternames
#保留注解
-keepattributes *Annotation*
#不裁剪多余代码
-dontshrink
-keep class 包名下aidl路径.*{
    public <methods>;
}
-keep class 包名.* {
    public <methods>;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值