0

我曾尝试制作资源库,但失败了。它在ideaJ(不是gradle项目)和eclipse中运行良好。

例如在 gradle 中,我的应用程序由三部分组成: 1. 主应用程序 2. 库 1 3. 库 2 :资源

当我使用 1 构建 1 + 3 和 3 的资源时效果很好。但是使用 in 2 构建 1 + 2 + 3 和 3 的资源会导致构建崩溃:

错误:包 com.example.kwangjo.mylibrary.R 不存在。

以下是 build.gradle 文件。

app : 
apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.kwangjo.testdd"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':mylibrary')
}

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

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
~           
library 2:
android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

setting.gradle
include ':app', ':mylibrary', ':mylibrary2'

what is the problem? It seems that aar file dose not provide resource R.class file for library build.

Anyone know how to enable this?
4

0 回答 0