當前位置:首頁 » 安卓系統 » android資源打包jar

android資源打包jar

發布時間: 2024-07-02 02:39:29

㈠ android如何將res文件夾下的資源打包到jar中

1.打包時,將資源放在asset文件夾內,通過AssetsManager獲取指定資源: 目標應用和jar中的assets文件夾會合並,所以可以通過獲取該應用的此類文件夾來獲取目標資源 2.使用library項目 此類方法不能混淆代碼,也就是說發布時需要提供library源項目.在引用此lib的目標項目中會看到一個包含已經編譯成class.dex的jar文件,這個文件反編譯以後仍然是只有代碼部分。 3.使用雙重library項目 提供一種雙層library項目的方法,可以混淆代碼,但是xml與圖片資源仍然是暴露的,且發布時需要提供二級引用項目,操作上復雜度較高,不如直接提供jar包和資源 4.直接提供jar包和資源(分開) 依然是反射R文件,資源會被暴露給開發者。

㈡ 如何使用Android Studio打包混淆的Jar

使用AS打包混淆Jar包,網路一下,一片一片的,但是很多都是零零散散的寫得不是很詳細或是直接拷貝,按照他們的教程測試總不是很順利,所以這里我就把我個人學習AS打包混淆Jar的成果總結出來,希望對大家有幫助。個人覺得寫得還是比較詳細的

使用gradle混淆打包Jar

使用AS開發項目,引入第三方庫是非常方便的,我們只需要在build.gradle中配置一行代碼就可以輕松引入我們需要的開發庫。那麼gradle可以幫我們混淆打包Jar嗎?答案是當然可以!

那麼我們如何打包Jar呢?其實我們在編譯項目的時候,AS已經幫我們在目錄build/intermediates/bundles/release/classes.jar打好了Jar。那麼我們需要做的就是把Jar進行混淆的工作了。這里以個人項目bannerDemo為例,混淆步驟如下:

在你的library的build.gradle文件中加入如下代碼:

task makeJar(type: proguard.gradle.ProGuardTask, dependsOn: "build") {
// 未混淆的jar路徑
injars 'build/intermediates/bundles/release/classes.jar'
// 混淆後的jar輸出路徑
outjars 'build/outputs/cocolove2-banner-1.1.0.jar'
// 混淆協議
configuration 'proguard-rules.pro'}

配置混淆協議

1.我們先把AS自帶的協議配置進來中文注釋,筆者添加

# This is a configuration file for ProGuard.# http://proguard.sourceforge.net/index.html#manual/usage.html## Starting with version 2.2 of the Android plugin for Gradle, these files are no longer used. Newer# versions are distributed with the plugin and unpacked at build time. Files in this directory are# no longer maintained.#表示混淆時不使用大小寫混合類名-dontusemixedcaseclassnames#表示不跳過library中的非public的類-#列印混淆的詳細信息-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.-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService-keep public class com.android.vending.licensing.ILicensingService# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native-keepclasseswithmembernames class * {
native <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);
}# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

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

-keepclassmembers class **.R$* {
public static <fields>;
}# 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.-dontwarn android.support.**# Understand the @Keep support annotation.-keep class android.support.annotation.Keep-keep @android.support.annotation.Keep class * {*;}-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}

2.AS自帶的配置文檔還是不夠的,我們還需要加入如下配置
這里只展示基本操作,在實際開發中可能需要更多依賴,要根據具體情況引入自己需要的依賴包

#下面代碼中的xx是指我個人的配置路徑,涉及個人信息,這里以xx代替
#引入依賴包rt.jar(jdk路徑)
-libraryjars /xxx/xx/xx/jdk1.8.0_77.jdk/Contents/Home/jre/lib/rt.jar
#引入依賴包android.jar(android SDK路徑)
-libraryjars /xx/xx/xx/Android/sdk/platforms/android-24/android.jar
#如果用到Appcompat包,需要引入
-libraryjars /xxx/xxx/xx/xxx/MyApplication/library-banner/build/intermediates/exploded-aar/com.android.support/appcompat-v7/24.1.1/jars/classes.jar
-libraryjars /xx/xx/xx/xx/MyApplication/library-banner/build/intermediates/exploded-aar/com.android.support/support-v4/24.1.1/jars/classes.jar

#忽略警告
-ignorewarnings
#保證是獨立的jar,沒有任何項目引用,如果不寫就會認為我們所有的代碼是無用的,從而把所有的代碼壓縮掉,導出一個空的jar
-dontshrink
#保護泛型
-keepattributes Signature

3.加入自己不想混淆的配置根據實際需求配置

-keep class com.cocolove2.library_banner.view.**{*;}

在命令行執行命令混淆Jar,提示BUILD SUCCESFUL表示成功!

//mac./gradlew makeJar//windowsgradlew makeJar

示例展示

  • 我這里以混淆library-banner庫為例

  • 1.首先我們要看看下我們的buildTool的配置,如下圖:


    [email protected]

    混淆報錯解決辦法個人遇到的

  • #log提示缺少依賴Jar,或者路徑不對


  • 解決辦法:乖乖的引入缺少的依賴jar和修改路徑

  • #提示如下異常[INFO] java.io.IOException: Can't read [D:Program

  • FilesJavajdk1.8.0_91jrelib t.jar] (Can't process class [com/oracle/net/Sdp$1.class] (Unsupported class version number

  • [52.0] (maximum 51.0, Java 1.7)))


  • 解決辦法:

  • 下載最新proguard(支持Java 8的版本),然後將下載的文件解壓

  • 將andorid sdk/tools/proguard/lib中的jar包,替換為剛下載解壓文件中的lib包。

  • proguard5.2.1下載地址

  • 閱讀

㈢ 如何將一個完整的Android工程打包成jar包

右鍵項目--build path--左邊點擊android--右邊有一個「is library」,勾選住,apply,ok。在項目的bin裡面會生成一個jar,就是項目的jar

㈣ Android 將引用的第三方jar包一起打成jar包

你打包android處於什麼目的呢?
如果的android項目不包括任何資源引用(layout,image)等,而純粹是個公共類庫。那麼建議直接新建一個java project。該project引用android Library。
如果你的android項目包括資源引用。那麼不建議將其打包成jar。建議將其作為library project。方法很簡單,右擊屬性。選擇android,勾選isLibrary。引用時只需要在屬性中選擇addLibrary即可。

㈤ android studio 怎麼將so打包成jar

主要思想: 1:將所有的so文件打包進一個jar文件; 2:將這個jar文件作為依賴文件; 我不會寫Goovy的代碼,下面這些都是我從上面那些參考頁面抄的,大概意思能看懂,如果有問題,請指正 代碼 task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') { destinationDir file("$buildDir/native-libs") baseName 'native-libs' extension 'jar' from(new File(project(':MyProject').getProjectDir(), 'libs')) { include '**/*.so' } into 'lib/' from(new File(project(':library').getProjectDir(), 'libs')) { include '**/*.so' } into 'lib/' } tasks.withType(Compile) { compileTask -> compileTask.dependsOn(nativeLibsToJar) }

㈥ 如何將一個完整的Android工程打包成jar包

將一個完整的Android工程打包成jar包步驟:

1、右鍵工程--->Export

2、點擊Java--->JAR file---->Next如下圖

3、勾選src包即可,其他項不選

4、點擊finishi即可,在D盤就可以看到library的jar包

5、其他應用程序引用就可以。

熱點內容
忍3什麼配置可以過精7 發布:2024-07-04 03:52:21 瀏覽:842
java防止反編譯 發布:2024-07-04 03:43:06 瀏覽:617
資料庫許可權控制 發布:2024-07-04 03:42:34 瀏覽:73
傳奇地圖觸發腳本 發布:2024-07-04 03:27:43 瀏覽:711
傳統的資料庫模型 發布:2024-07-04 03:22:45 瀏覽:391
sql2000資料庫導入資料庫 發布:2024-07-04 03:18:27 瀏覽:276
oraclesql計算時間差 發布:2024-07-04 03:09:11 瀏覽:120
搭建起來的雲伺服器 發布:2024-07-04 03:04:21 瀏覽:227
c51編譯環境設置 發布:2024-07-04 03:02:53 瀏覽:947
sqlserver優化 發布:2024-07-04 02:46:32 瀏覽:903