Android Studio 编译生成Jar(Linux)

  • 模块build.grade
plugins {
    id 'com.android.library'
}

android {
    compileSdk 32

    defaultConfig {
        minSdk 28
        targetSdk 32

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

//Copy类型
task makeJar(type: Copy) {
    //删除存在的
    delete 'build/libs/mdm.jar'
    //设置拷贝的文件
    // from('build/intermediates/bundles/release/')
    from('build/intermediates/aar_main_jar/release/')
    //打进jar包后的文件目录
    into('build/libs/')
    //将classes.jar放入build/libs/目录下
    //include ,exclude参数来设置过滤
    //(我们只关心classes.jar这个文件)
    include('classes.jar')
    //重命名
    rename ('classes.jar', 'mdm.jar')
}

makeJar.dependsOn(build)
//在终端执行生成JAR包
// gradlew makeJar
  • Terminal中运行
    ./gradlew makeJar (Linux)
    gradlew makeJar (Window)

你可能感兴趣的:(android,Android,Studio,android,studio,jar,linux)