我已经尝试使用旧的预构建源进行 Jetpack 组合。但最近我下载了一个新资源,但它对我不起作用。这是我尝试过的。
我在 Project/androidx_prebuilts/out/ui/build/support_repo/androidx 中添加了源
在 androidx 目录下,我有源代码的compose和ui目录
模块级gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
maven { url "$androidx_home/out/ui/build/support_repo/" }
google()
jcenter()
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.compose.app"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
// typeuseIR = true
freeCompilerArgs += "-P"
freeCompilerArgs +=
"plugin:androidx.compose.plugins.kotlin:syntax=FCS"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.core:core-ktx:1.0.2"
implementation "androidx.compose:compose-runtime:1.0.0-alpha01"
implementation "androidx.ui:ui-animation:1.0.0-alpha01"
implementation "androidx.ui:ui-animation-core:1.0.0-alpha01"
implementation "androidx.ui:ui-android-view:1.0.0-alpha01"
implementation "androidx.ui:ui-android-view-non-ir:1.0.0-alpha01"
implementation "androidx.ui:ui-android-text:1.0.0-alpha01"
implementation "androidx.ui:ui-core:1.0.0-alpha01"
implementation "androidx.ui:ui-framework:1.0.0-alpha01"
implementation "androidx.ui:ui-layout:1.0.0-alpha01"
implementation "androidx.ui:ui-material:1.0.0-alpha01"
implementation "androidx.ui:ui-platform:1.0.0-alpha01"
implementation "androidx.ui:ui-text:1.0.0-alpha01"
testImplementation "junit:junit:4.12"
androidTestImplementation "androidx.test:runner:1.1.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
}
应用程序等级
buildscript {
ext.kotlin_version = "1.3.41"
ext.androidx_home = project.properties["androidx.home"] ?: "$projectDir/androidx_prebuilts"
repositories {
maven { url "$androidx_home/out/ui/build/support_repo/" }
maven {
url "http://dl.bintray.com/kotlin/kotlin-eap"
}
mavenLocal()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0-alpha09'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'idea'
idea.module {
excludeDirs += file('$projectDir/androidx_prebuilts')
}
allprojects {
repositories {
maven {
url "https://dl.bintray.com/kotlin/kotlin-dev/"
}
maven { url "$androidx_home/out/ui/build/support_repo/" }
mavenLocal()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我在构建项目时遇到的错误
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not find androidx.compose:compose-runtime:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-animation:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-animation-core:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-android-view:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-android-view-non-ir:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-android-text:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-core:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-framework:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-layout:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-material:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-platform:1.0.0-alpha01.
Required by:
project :app
> Could not find androidx.ui:ui-text:1.0.0-alpha01.
Required by:
project :app