Jetpack撰写新资源无法正常工作

时间:2019-09-04 13:38:25

标签: android androidx android-jetpack-compose

我已经尝试过用旧的prebuild源码构建Jetpack。但是最近我下载了一个新资源,但对我来说不起作用。这是我尝试过的。

  

我在中添加了源    项目/ androidx_prebuilts / out / ui / build / support_repo / androidx

在androidx目录下,我有composeui目录作为源文件

  

模块级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"
}
  

应用程序级别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
}
  

我在构建项目时遇到错误

  * 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

3 个答案:

答案 0 :(得分:1)

首先,请参阅此文档:googlesource

”“本节介绍如何设置本地工作环境以构建Android源文件。您必须使用Linux或macOS;当前不支持在Windows下进行构建。” — Android文档

  

步骤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

  

第2步:

创建目录,说“ AndroidCompose”

mkdir ~/AndroidCompose
cd ~/AndroidCompose

和设置git config一样(如果未设置)

git config — global user.name “Your Real Name”
git config — global user.email “you@example.com”

现在初始化仓库

repo init -u https://android.googlesource.com/platform/manifest -b androidx-master-dev

现在回购已初始化,如果我们查看〜/ AndroidCompose目录,我们将看到一个“ .repo”清单

点击

ls -a ~/AndroidCompose/.repo

“现在,您的存储库已设置为仅提取构建和运行AndroidX库所需的资源。下载代码(在我们提取6GB的同时喝咖啡)” -Android文档

  

步骤3:   获取所有必需来源的命令

repo sync -j8 -c

(类似于git fetch)

现在,我们已经下载了包含@Composable的正确版本的Android JetPack源

这会将所有Jetpack Compose源代码放置在“ ui”目录中

cd ~/AndroidCompose/frameworks/support/ui

点击

./studiow 启动Android Studio

重新启动Android Studio时要小心。我们需要始终从该目录开始以获取Jetpack Compose库。

在出现提示时接受许可协议。现在我们可以编辑,运行和测试了!

答案 1 :(得分:1)

jetpack compose UI组件构建现已作为开发版本提供。 您不必使用Special android studio。只需以“ 0.1.0-dev01”作为版本包含所有Compose Gradle依赖项

更新:现在,Android Studio 4.0 Canary随附了Jetpack Compose和实时预览功能。

答案 2 :(得分:0)

我也遇到了这个问题,然后我找到了一个对我来说很好的解决方案。 我正在与您共享该URL。

https://github.com/Mishkun/try-compose