库res / raw和res / xml资源未包含在aar文件中

时间:2018-10-21 14:24:55

标签: android android-library aar

res / raw和res / xml资源未包含在aar文件中,原始文件夹包含keep.xml,而xml文件夹包含backup_rules.xml。它们均不包含在aar文件中,提取的aar文件中的raw和xml文件夹为空。 我应该如何将它们包含在aar输出中?

更新1,添加gradle项目和库gradle文件。

项目Gradle文件

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.google.gms:google-services:4.0.1'
    }
}


def versionMajor = 4
def versionMinor = 0
def versionPatch = 1
def versionBuild = 0

allprojects {
    repositories {
        jcenter()
        google()
    }

    project.version = "${versionMajor}.${versionMinor}.${versionPatch}"

}

ext {
    configCompileMinSdkVersion = 14
    configCompileSdkVersion = 28
    configTargetSdkVersion = 28
    configVersionCode = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

库gradle文件

apply plugin: 'com.android.library'

android {
    lintOptions {
        abortOnError false
    }

    compileSdkVersion configCompileSdkVersion
    defaultConfig {
        defaultPublishConfig 'release'
        publishNonDefault true
        minSdkVersion configCompileMinSdkVersion
        targetSdkVersion configTargetSdkVersion
        versionCode configVersionCode
        versionName project.version
        consumerProguardFiles 'proguard-rules.pro'
        project.archivesBaseName = "my_sdk"
        project.version = android.defaultConfig.versionName


    }
    buildTypes {
        debug {
            debuggable true
            versionNameSuffix '-debug'
            buildConfigField("String", "SDK_TYPE", "\"android\"" )
        }

        release {
            versionNameSuffix 'release'
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            buildConfigField("String", "SDK_TYPE", "\"android\"" )
        }

        unity {
            versionNameSuffix 'unity'
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            buildConfigField("String", "SDK_TYPE", "\"unity\"" )
        }
    }

    libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.aar')) {
                def f = outputFile.name.replace(".aar", "")
                if(f != null && f.contains("release")) {
                    f = f.replace("-release", "")
                }

                def fileName = "${f}-${version}.aar"
                fileName = fileName.replace("_", "-")

                output.outputFileName = new File("release", fileName)
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation "com.google.android.gms:play-services-gcm:16.0.0"
    implementation 'android.arch.work:work-runtime:1.0.0-alpha08'
}

更新2,添加项目结构。

enter image description here

0 个答案:

没有答案