android studio 將library導出為jar 親測成功


本人使用的是helloChart這個開源項目,其主要用於圖表,來自git 地址為:https://github.com/lecho/hellocharts-android

下載命令為 git clone https://github.com/lecho/hellocharts-android.git

由於項目需求修改了hellocharts-library這個module中的源碼,並且集成進eclipse項目因此需要制作jar包。也可以自己新建library module項目嘗試。

步驟一:(mac下)添加全局變量gradle,打開終端,輸入gradle,出現下面信息表示以成功添加全局的gradle,若沒有則打開Finder➡️應用程序➡️Android studio.app➡️點擊鼠標右鍵選擇“顯示包內容”➡️Contents➡️gradle➡️gradle-2.10(可能與你不一致但差不多)➡️bin,打開終端將bin目錄拖入,獲取bin目錄的絕對路徑,接着打開bash_profile設置全局,輸入命令:open -t ~/.bash_profile 會打開一個文件,添加一下export PATH=$PATH:/Applications/Android\ Studio.app/Contents/gradle/gradle-2.10/bin其中冒號:之后的為剛剛獲取的bin的絕對路徑,保存后關閉。之后在終端中輸入gradle,顯示以下圖片內容(注意:bash_profile 操作與windows下設置環境變量效果相同,不清楚請先百度。)

步驟二:打開屬於hellocharts-library項目的build.gradle,在文件的最最末尾(最后一個“}”下面)輸入以下代碼保存。其中helloChart為需要保存的文件名。

task makeJar(type: Copy) {
    delete 'build/libs/helloChart.jar'
    from('build/intermediates/bundles/release/')
    into('build/libs/')
    include('classes.jar')
    rename ('classes.jar', 'helloChart.jar')
}
makeJar.dependsOn(build)

步驟三:cd 命令進入hellocharts-library文件夾 輸入命令  gradle makeJar

xxxxdeMacBook-Pro:hellocharts-library minyuchun$ gradle makeJar

如果為第一次使用程序應該會下載與mave2有關的內容,等着讓它下,內容不多,最后在爆出100個警告后終端中輸出以下內容

:hellocharts-library:prepareReleaseUnitTestDependencies
:hellocharts-library:compileReleaseUnitTestJavaWithJavac UP-TO-DATE
:hellocharts-library:processReleaseUnitTestJavaRes UP-TO-DATE
:hellocharts-library:compileReleaseUnitTestSources UP-TO-DATE
:hellocharts-library:assembleReleaseUnitTest UP-TO-DATE
:hellocharts-library:testReleaseUnitTest
:hellocharts-library:test
:hellocharts-library:check
:hellocharts-library:build
:hellocharts-library:makeJar

BUILD SUCCESSFUL

Total time: 8 mins 2.892 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html

我們就可以查看下 hellocharts-library下的build下的libs下是否存在helloChart.jar文件。將其拷貝如項目嘗試。

eslipse中的library項目導出  http://blog.csdn.net/wwj_748/article/details/21937257

若出現文件出錯請先解決代碼中waring警告,clean代碼后重新導出。

注意:在制作jar包的時候 盡量注意要制作的項目的版本,最好是版本一樣或者低版本。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM