如何从android studio创建一个jar文件?

时间:2016-01-20 10:07:43

标签: android android-studio

  

如何从Android项目创建jar文件,其中包含android studio中的facebook库和viewPager库

1 个答案:

答案 0 :(得分:1)

  

它为我工作

     
      
  1. 输入您的java源文件
  2.   
  3. 更改您的清单文件,如下所示
  4.   
Manifest File:

apply plugin: 'com.android.library'  
android 
{      
compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig 
   {

        minSdkVersion 15
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile project(':facebook')
}
task deleteOldJar(type:Delete){
    delete 'release/FacebookSharingApi.jar'
}
task exportJar(type:Copy){
from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    rename('classes.jar','FacebookSharingApi.jar')
}
exportJar.dependsOn(deleteOldJar,build)
  
      
  1. 点击expostJar(任务)---按照以下步骤
  2.   
    > Right side of your android studio 
    > --- Gradle 
       --- Gradle project 
         ---   click refresh button 
            --- app ---others -- (ExportJar)