在 Android 个移动和磨损模块之间共享文件
Sharing files between Android mobile and wear modules
几个月前,我最初只是用一个移动模块开始我的项目,现在我也有兴趣为可穿戴设备配置我的应用程序。也就是说,我所有的文件(Java、XML、drawables 等)都在移动模块中,所以我需要传输所有我想在移动设备和穿戴设备之间共享的文件吗模块到新创建的 "common" 模块?
编辑:
有人可以向我解释以下来自移动设备和可穿戴设备 Gradle 文件的 Gradle 项目同步错误是什么意思:
... 这发生在我在两个模块中包含 compile project(':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,但我得到了与上面所示相同的错误。
正确,如果你的文件被两个模块(移动和穿戴)使用,那么显然,你应该让这两个模块使用一个共享模块,你可以在其中放置所有必要的文件。
在每个模块中添加 compile project(': common')
如前所述here:
1- 确保 build.gradle (Module:my-library-module)
中的第一行正确定义为:
apply plugin: 'com.android.library'
2- 将库添加到 settings.gradle
为:
include ':app', ':my-library-module'
3- 将 build.gradle (Module:xxx)
(Module:mobile) 中的库编译为:
dependencies {
compile project(":my-library-module")
}
4- 在您的项目中,import
库为:
import xxx.xx.xx
几个月前,我最初只是用一个移动模块开始我的项目,现在我也有兴趣为可穿戴设备配置我的应用程序。也就是说,我所有的文件(Java、XML、drawables 等)都在移动模块中,所以我需要传输所有我想在移动设备和穿戴设备之间共享的文件吗模块到新创建的 "common" 模块?
编辑:
有人可以向我解释以下来自移动设备和可穿戴设备 Gradle 文件的 Gradle 项目同步错误是什么意思:
... 这发生在我在两个模块中包含 compile project(':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,但我得到了与上面所示相同的错误。
正确,如果你的文件被两个模块(移动和穿戴)使用,那么显然,你应该让这两个模块使用一个共享模块,你可以在其中放置所有必要的文件。
在每个模块中添加 compile project(': common')
如前所述here:
1- 确保 build.gradle (Module:my-library-module)
中的第一行正确定义为:
apply plugin: 'com.android.library'
2- 将库添加到 settings.gradle
为:
include ':app', ':my-library-module'
3- 将 build.gradle (Module:xxx)
(Module:mobile) 中的库编译为:
dependencies {
compile project(":my-library-module")
}
4- 在您的项目中,import
库为:
import xxx.xx.xx