在Android移动设备和佩戴模块之间共享文件

时间:2016-03-20 17:55:08

标签: android android-studio module wear-os

几个月前,我最初只使用移动模块启动了我的项目,现在我也有兴趣为可穿戴设备配置我的应用程序。也就是说,我的所有文件(Java,XML,drawables等)都在移动模块中,所以我需要将所有想要在移动和磨损模块之间共享的文件传输到新创建的“通用”中模块?

修改

有人可以向我解释以下Gradle项目同步错误来自手机和磨损的Gradle文件是什么意思:

enter image description here

...这是在我在两个模块中包含 编译项目(':common') 之后发生的,如下所示:

首先,这是我的常用模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "dpark.gameoflife"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
}

移动模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "dpark.gameoflife"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    wearApp project(':wear')
    compile project(':common')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.google.android.gms:play-services:8.4.0'
}

最后,我的穿戴模块:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "dpark.gameoflife"
        minSdkVersion 20
        targetSdkVersion 23
        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.google.android.support:wearable:1.3.0'
    compile 'com.google.android.gms:play-services-wearable:8.4.0'
    compile project(':common')
}

......如果有的话,我在发布模式下签署了我公共模块的APK,但是我得到的错误如上所示。

2 个答案:

答案 0 :(得分:2)

正确,如果您的文件被两个模块(移动和磨损)使用,那么显然,您应该使这两个模块使用共享模块放置所有必要的文件。

在每个模块中添加compile project(': common')

答案 1 :(得分:0)

如上所述here

1-确保build.gradle (Module:my-library-module)中的第一行正确定义为:

apply plugin: 'com.android.library'

2-将库添加到settings.gradle as:

include ':app', ':my-library-module'

3-将build.gradle (Module:xxx)(模块:移动设备)中的库编译为:

dependencies {
    compile project(":my-library-module")
}

4-在您的项目中,import图书馆为:

import xxx.xx.xx