2017-11-17 11 views
1

나는 하나의 안드로이드 라이브러리 모듈을 가진 안드로이드 프로젝트를 가지고 있지만, 전통적인 방식으로 사용하고 싶지 않습니다.dex jar 및 c 라이브러리를 추출하는 데 gradle 작업을 어떻게 설정할 수 있습니까?

내가 지금하는 일은 조립 작업 ( gradle 작업)과 결과 * .aar 파일을 후 처리하는 것입니다.

내가하는 Gradle을 작업 만들고 싶습니다

  1. 가 classes.jar 및이 (비슷한 덱스에 --dx ...) 그것을이야 덱스를 빌드;
  2. 기본 라이브러리를 빌드하십시오.
  3. 내가 선택할 수있는 폴더의 모든 항목을 이동합니다.

불행히도, 난 단지 (임베디드 Gradle을 작업 externalNativeBuildRelease와) 네이티브 라이브러리를 구축 할 수있는 방법을 발견했다.

아무도이 그루비 그라데 문제를 해결할 수 있습니까?

답변

2

여기에 에서 추출한 내용의 대부분은 아니지만 모두를 수행하는 파일 인 build.gradle가 있습니다.
this 대답에 사용했습니다.
The Gradle build system- TutorialWriting Custom Tasks도 참조하십시오. 여기

정의 된 작업입니다 :

  • 작업 copyClasses
  • 작업 assembleExternalJar
  • 작업 copyJarToOutputs

그것은 당신에게 당신이 원하는 것을 할 수있는 영감을 제공한다 :

import org.apache.tools.ant.taskdefs.condition.Os 

//jrg 
apply plugin: 'com.android.library' 
//apply plugin: 'com.android.application' 

android { 
    compileSdkVersion Integer.parseInt(COMPILE_SDK) 
    buildToolsVersion BUILD_TOOLS_VERSION 

    defaultConfig { 
     targetSdkVersion Integer.parseInt(TARGET_SDK) 
     minSdkVersion Integer.parseInt(MIN_SDK) 
    } 
} 
// Add the main project as a dependency for our library 
dependencies { 
    compile project(':app') 
} 
// Define some tasks which are used in the build process 
task copyClasses(type: Copy) { // Copy the assembled *.class files for only the current namespace into a new directory 
    // get directory for current namespace 
    def namespacePath = PLUGIN_NAMESPACE.replaceAll("\\.","/") 
    // set source and destination directories 
    from "build/intermediates/classes/release/${namespacePath}/" 
    into "build/intermediates/dex/${namespacePath}/" 

    // exclude classes which don't have a corresponding entry in the source directory 
    def remExt = { name -> name.lastIndexOf('.').with {it != -1 ? name[0..<it] : name} } 
    eachFile {details -> 
     def thisFile = new File("${projectDir}/src/main/java/${namespacePath}/", remExt(details.name)+".java") 
     if (!(thisFile.exists())) { 
      details.exclude() 
     } 
    } 
} 

task assembleExternalJar << { 
    // Get the location of the Android SDK 
    ext.androidSdkDir = System.env.ANDROID_HOME 
    if(androidSdkDir == null) { 
     Properties localProps = new Properties() 
     localProps.load(new FileInputStream(file('local.properties'))) 
     ext.androidSdkDir = localProps['sdk.dir'] 
    } 
    // Make sure no existing jar file exists as this will cause dx to fail 
    new File("${buildDir}/intermediates/dex/${PLUGIN_NAMESPACE}.jar").delete(); 
    // Use command line dx utility to convert *.class files into classes.dex inside jar archive 
    String cmdExt = Os.isFamily(Os.FAMILY_WINDOWS) ? '.bat' : '' 
    exec { 
     commandLine "${androidSdkDir}/build-tools/${BUILD_TOOLS_VERSION}/dx${cmdExt}", '--dex', 
        "--output=${buildDir}/intermediates/dex/${PLUGIN_NAMESPACE}.jar", 
        "${buildDir}/intermediates/dex/" 
    } 
    copyJarToOutputs.execute() 
} 

task copyJarToOutputs(type: Copy) { 
    // Copy the built jar archive to the outputs folder 
    from 'build/intermediates/dex/' 
    into 'build/outputs/' 
    include '*.jar' 
} 


// Set the dependencies of the build tasks so that assembleExternalJar does a complete build 
copyClasses.dependsOn(assemble) 
assembleExternalJar.dependsOn(copyClasses)