Jetpack 撰写新源不工作
Jetpack compose new source is not working
我已经尝试使用旧的预构建源代码编写 Jetpack。但是最近我下载了一个新源,但它对我不起作用。这是我试过的。
I have added source in
Project/androidx_prebuilts/out/ui/build/support_repo/androidx
在 androidx 目录下,我有 compose and ui 个源目录
Module level 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"
}
Application level gradle
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
}
Error I'm getting while building the project
* 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
我也遇到过这个问题,然后我找到了一个适合我的解决方案。
我正在与您分享 URL。
首先,参考这个文档:googlesource
"This section describes how to set up your local work environment to build the Android source files. You must use Linux or macOS; building under Windows is not currently supported." — Android 文档
Step 1:
首先,我们需要从(如果没有安装)安装 Repo
https://source.android.com/setup/build/downloading
并在命令行中点击以下命令
mkdir bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
现在检查repo status
Step 2:
创建一个目录假设 "AndroidCompose"
mkdir ~/AndroidCompose
cd ~/AndroidCompose
并设置 git 配置(如果未设置)
git config — global user.name “Your Real Name”
git config — global user.email “you@example.com”
现在初始化 repo
repo init -u https://android.googlesource.com/platform/manifest -b androidx-master-dev
repo 现已初始化,如果我们查看 ~/AndroidCompose 目录,我们将看到一个“.repo”列表
命中
ls -a ~/AndroidCompose/.repo
"Now your repository is set to pull only what you need for building and running AndroidX libraries. Download the code (and grab a coffee while we pull down 6GB)" -Android 文档
Step 3:
Command to get all required source
repo sync -j8 -c
(类似于git fetch)
现在我们已经下载了正确版本的 Android JetPack 源代码,其中包含 @Composable
这会将所有 Jetpack Compose 源放在 "ui" 目录中
cd ~/AndroidCompose/frameworks/support/ui
命中
./studiow
开始 Android 工作室
重新启动时要小心 Android Studio。我们需要始终从该目录开始获取 Jetpack Compose 库。
出现提示时接受许可协议。现在我们可以编辑了,运行,然后测试!
jetpack compose UI 组件构建现在可以作为开发版本使用。
您不必使用 Special android 工作室。只需包含所有 compose Gradle 依赖项,并将“0.1.0-dev01”作为版本
更新:现在 Android Studio 4.0 Canary 附带 Jetpack Compose 和实时预览,开箱即用。
我已经尝试使用旧的预构建源代码编写 Jetpack。但是最近我下载了一个新源,但它对我不起作用。这是我试过的。
I have added source in Project/androidx_prebuilts/out/ui/build/support_repo/androidx
在 androidx 目录下,我有 compose and ui 个源目录
Module level 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"
}
Application level gradle
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
}
Error I'm getting while building the project
* 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
我也遇到过这个问题,然后我找到了一个适合我的解决方案。 我正在与您分享 URL。
首先,参考这个文档:googlesource
"This section describes how to set up your local work environment to build the Android source files. You must use Linux or macOS; building under Windows is not currently supported." — Android 文档
Step 1:
首先,我们需要从(如果没有安装)安装 Repo https://source.android.com/setup/build/downloading
并在命令行中点击以下命令
mkdir bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
现在检查repo status
Step 2:
创建一个目录假设 "AndroidCompose"
mkdir ~/AndroidCompose
cd ~/AndroidCompose
并设置 git 配置(如果未设置)
git config — global user.name “Your Real Name”
git config — global user.email “you@example.com”
现在初始化 repo
repo init -u https://android.googlesource.com/platform/manifest -b androidx-master-dev
repo 现已初始化,如果我们查看 ~/AndroidCompose 目录,我们将看到一个“.repo”列表
命中
ls -a ~/AndroidCompose/.repo
"Now your repository is set to pull only what you need for building and running AndroidX libraries. Download the code (and grab a coffee while we pull down 6GB)" -Android 文档
Step 3: Command to get all required source
repo sync -j8 -c
(类似于git fetch)
现在我们已经下载了正确版本的 Android JetPack 源代码,其中包含 @Composable
这会将所有 Jetpack Compose 源放在 "ui" 目录中
cd ~/AndroidCompose/frameworks/support/ui
命中
./studiow
开始 Android 工作室
重新启动时要小心 Android Studio。我们需要始终从该目录开始获取 Jetpack Compose 库。
出现提示时接受许可协议。现在我们可以编辑了,运行,然后测试!
jetpack compose UI 组件构建现在可以作为开发版本使用。 您不必使用 Special android 工作室。只需包含所有 compose Gradle 依赖项,并将“0.1.0-dev01”作为版本
更新:现在 Android Studio 4.0 Canary 附带 Jetpack Compose 和实时预览,开箱即用。