How to exclude files from aar with Gradle dynamically?

后端 未结 1 1263
春和景丽
春和景丽 2021-01-17 16:37

I\'m having android library (aar) that contains (and builds while building module) native code:

apply plugin: \'com.android.library\'

android {         


        
1条回答
  •  心在旅途
    2021-01-17 17:16

    Actually i was able to do it myself:

    apply plugin: 'com.android.library'
    
    android {
      compileSdkVersion 16
      buildToolsVersion "25.0.0"
    
      defaultConfig {
        minSdkVersion 11
        targetSdkVersion 16
        versionCode 1
        versionName "1.0"
    
        ndk {
          abiFilters 'armeabi-v7a'
        }
      }
    
      externalNativeBuild {
        ndkBuild {
          path 'jni/Android.mk'
        }
      }
    
      sourceSets {
        main {
          manifest.srcFile 'AndroidManifest.xml'
          java.srcDirs = ['src']
          res.srcDirs = ['res']
          jni.srcDirs = ['jni']
        }
      }
    
      def sharedV8LibFilesSet = []
      def sharedV8LibFiles = System.getenv('SHARED_V8_LIB_FILENAMES')
      if (sharedV8LibFiles != null) {
        def sharedV8LibFilesArray = sharedV8LibFiles.split(' ')
        sharedV8LibFilesArray.each { eachFileName ->
          sharedV8LibFilesSet.add("**/" + eachFileName)
          println "[Configuration] Excluding shared v8 library " + eachFileName + " from AAR"
        }
      } else {
        println "[Configuration] No shared v8 libraries excluded from AAR"
      }
    
      packagingOptions {
        excludes = sharedV8LibFilesSet
      }
    }
    

    Any code style changes/improvements appreciated.

    0 讨论(0)
提交回复
热议问题