初探:java
android studio生成Jar.
android
android studio 自動生成aar.
app
1.android studio 自動生成.jar, 首先將工程做爲依賴庫,build便可。
gradle
2.手動打包jar
ui
1> 僅打包class文件
spa
task makeJar(type: Jar, dependsOn:['build', 'targetJar']) { from file('build/intermediates/classes/release') //目標文件名稱 archiveName = 'un_proguard.jar' destinationDir = file('build/libs') exclude "lbs/tmplibary/BuildConfig.class" exclude "lbs/tmplibary/BuildConfig\$*.class" exclude "**/R.class" exclude "**/R\$*.class" //只導入資源路徑集下的部分資源 include "lbs/**/*.class" }
2>添加assets文件
code
(1)直接includes assets文件便可orm
task makeJar(type: Jar, dependsOn:['build', 'targetJar']) { from file('build/intermediates/classes/release') from fileTree(dir: 'src/main', includes: ['assets/**']) //目標文件名稱 archiveName = 'un_proguard.jar' destinationDir = file('build/libs') exclude "lbs/tmplibary/BuildConfig.class" exclude "lbs/tmplibary/BuildConfig\$*.class" exclude "**/R.class" exclude "**/R\$*.class" //只導入資源路徑集下的部分資源 include "lbs/**/*.class" include "assets/**" }
(2)使用zipTree
ip
將所需打包的assets文件打包成.zip,以下:資源
def zipFile = "src/main/assets.zip" task makeJar(type: Jar, dependsOn:['build', 'targetJar']) { from zipTree(zipFile) from file('build/intermediates/classes/release') //目標文件名稱 archiveName = 'un_proguard.jar' destinationDir = file('build/libs') exclude "lbs/tmplibary/BuildConfig.class" exclude "lbs/tmplibary/BuildConfig\$*.class" exclude "**/R.class" exclude "**/R\$*.class" //只導入資源路徑集下的部分資源 include "lbs/**/*.class" }
3.混淆
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: makeJar) { // 輸入路徑 injars "build/libs/un_proguard.jar" // 輸出路徑 outjars 'libs/app_proguard.jar' // 添加配置信息 configuration 'proguard-rules.pro' }
proguard-rules.pro須要配置一下路徑
-libraryjars <java.home>/lib/rt.jar -libraryjars xxxxx/android/sdk/platforms/android-22/android.jar
注:代碼編譯出錯的狀況下 添加
-dontpreverify
儘量的時候使用
-dontwarn
忽略一些沒必要要的警告,以便成功打包。
完結,~_~