Android apk to library

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 70202301
        versionName '7.2.2.301'

        multiDexEnabled true
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/lib']
        }
    }

    signingConfigs {
        release {
            storeFile file("../" + RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        // abortOnError false
    }
}

task apk2libraryTask() << {

    exec {
        executable "cmd"
        args "/c", "java -jar ../../apktool.jar d ../patched/build/outputs/apk/patched-release.apk -o src/main --force"
    }

    delete 'src/main/smali/android/support'
    delete 'src/main/original'
    //delete 'src/main/apktool.yml'

    def manifestFile = file('src/main/AndroidManifest.xml')
    def contents = manifestFile.getText('UTF-8')
    contents = contents.replace("package=\"com.babybus.appmarket\"", "package=\"com.babybus.appmarket.library\"")
    manifestFile.write(contents, 'UTF-8')

    exec {
        executable "cmd"
        args "/c", "java -jar ../../smali-2.2.0.jar assemble src/main/smali"
    }

    exec {
        executable "cmd"
        args "/c", "dex2jar out.dex -o libs/classes-dex2jar.jar --force"
    }

    delete 'out.dex'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:multidex:1.0.1'

    compile 'com.android.support:support-v4:25.3.1'
    compile "com.android.support:appcompat-v7:25.3.1"
    compile "com.android.support:support-v13:25.3.1"
}

// afterEvaluate {
//     for (variant in android.libraryVariants) {
//         def scope = variant.getVariantData().getScope()
//         String mergeTaskName = scope.getMergeResourcesTask().name
//         def mergeTask = tasks.getByName(mergeTaskName)

//         mergeTask.doLast {
//             copy {
//                 int i=0
//                 from(android.sourceSets.main.res.srcDirs) {
//                     include 'values/public.xml'
//                     rename 'public.xml', (i++ == 0? "public.xml": "public_${i}.xml")
//                 }

//                 into(mergeTask.outputDir)
//             }
//         }
//     }
// }

你可能感兴趣的:(Android apk to library)