【发布时间】:2021-03-25 14:38:55
【问题描述】:
我正在开发 Wear OS 上的表盘。我有一个用于许多不同项目的核心模块,其中包含所有通用代码。
特别是,我有这个复杂样式的 xml 文件:
<drawable
xmlns:app="http://schemas.android.com/apk/res-auto"
class="android.support.wearable.complications.rendering.ComplicationDrawable"
app:backgroundColor="@android:color/transparent"
app:borderColor="@android:color/transparent"
app:borderDashGap="0dp"
app:borderDashWidth="1dp"
app:borderRadius="52dp"
app:borderStyle="solid"
app:borderWidth="3dp"
app:highlightColor="@android:color/transparent"
app:iconColor="@color/white"
app:rangedValuePrimaryColor="@android:color/transparent"
app:rangedValueRingWidth="2.5dp"
app:rangedValueSecondaryColor="@android:color/transparent"
app:textColor="@color/white"
app:textSize="12sp"
app:textTypeface="sans-serif-condensed"
app:titleColor="@color/white"
app:titleSize="12sp"
app:titleTypeface="sans-serif">
<ambient
app:highlightColor="@color/white"
app:iconColor="@color/white"
app:titleColor="@color/white"
app:borderColor="@android:color/transparent"
app:rangedValuePrimaryColor="@android:color/transparent"
app:rangedValueRingWidth="1dp"
app:rangedValueSecondaryColor="@android:color/transparent"
app:textColor="@color/white"
/>
</drawable>
文件是这样调用的:
val drawable = ContextCompat.getDrawable(context,R.drawable.custom_complication_styles) as ComplicationDrawable
最初,一切顺利(在外观上),我的项目编译得很好(在调试模式下)。但后来我注意到 Android Studio 抱怨我的核心模块存在 gradle 依赖关系。他想让我代替
api "com.google.android.wearable:wearable:2.8.1"
api "com.google.android.support:wearable:2.8.1"
通过
compileOnly "com.google.android.wearable:wearable:2.8.1"
compileOnly "com.google.android.support:wearable:2.8.1"
问题是这样做会触发以下错误:
AAPT:错误:未找到属性边框颜色(又名 com.myapp:borderColor)。
上述 xml 文件中的几乎每个属性都会触发相同的错误。
此外,错误链接到自动生成的中间文件,而不是原始文件。我不知道这是否正常。在那个文件上,我提到了这个错误:
如果相关,这里是我的核心模块的完整 gradle 文件:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-parcelize'
}
android {
compileSdkVersion COMPILE_SDK_VERSION
buildToolsVersion BUILD_TOOL_VERSION
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 24
targetSdkVersion TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
signingConfigs {
release {
keyAlias 'bs23'
keyPassword '123456'
storeFile file("$rootDir/keystore/android.jks")
storePassword '123456'
}
debug {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file("$rootDir/keystore/debug.keystore")
storePassword 'android'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
debuggable false
}
debug {
signingConfig signingConfigs.debug
}
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.gms:play-services-location:17.1.0'
api 'com.google.android.gms:play-services-wearable:17.0.0'
api 'androidx.fragment:fragment-ktx:1.3.1'
compileOnly 'com.google.android.gms:play-services-fitness:20.0.0'
compileOnly 'com.google.android.gms:play-services-auth:19.0.0'
compileOnly "com.google.android.wearable:wearable:$wearable_version"
compileOnly "com.google.android.support:wearable:$wearable_version"
api 'androidx.wear:wear:1.1.0'
api "androidx.core:core-ktx:1.3.2"
api 'com.android.billingclient:billing:2.1.0'
api 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.libraries.places:places:2.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
//RX
api 'io.reactivex.rxjava2:rxjava:2.2.19'
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
所以在 'api' 和 'compileOnly' 之间来回移动会使我的项目编译或不编译。我不知道我做错了什么。
【问题讨论】:
标签: android android-studio data-binding wear-os