Страницы

Поиск по вопросам

Показаны сообщения с ярлыком androidx. Показать все сообщения
Показаны сообщения с ярлыком androidx. Показать все сообщения

четверг, 9 января 2020 г.

Добавление зависимости androidx

#android #gradle #androidx


Файл build.gradle выглядит следующим образом:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.recyclerviewexample"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
}


Но в результате сборки ошибки:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources,
:app:mockableAndroidJar]
C:\Users\Xu\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0-beta01.aar\45f296cd7466b0137ad2b0b5868320be\res\values-v28\values-v28.xml
Error:(9, 5) error: resource android:attr/dialogCornerRadius not found.
C:\Users\Xu\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0-beta01.aar\45f296cd7466b0137ad2b0b5868320be\res\values\values.xml
Error:(1304, 5) error: resource android:attr/fontVariationSettings not found.
Error:(1304, 5) error: resource android:attr/ttcIndex not found.
D:\Android Projects\RecyclerViewExample\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml
Error:(11) error: resource android:attr/dialogCornerRadius not found.
Error:(7) resource android:attr/dialogCornerRadius not found.
Error:(11) resource android:attr/dialogCornerRadius not found.
D:\Android Projects\RecyclerViewExample\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
Error:(231) resource android:attr/fontVariationSettings not found.
Error:(231) resource android:attr/ttcIndex not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException:
com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception:
AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 7s
Information:13 errors
Information:0 warnings
Information:See complete output in console


При этом, если блок dependencies выглядит так:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
}


то сборка проходит успешно. Как добавить зависимость androidx в проект? Версия Android
Studio - 3.0.1.
    


Ответы

Ответ 1



Согласно доке New Project If you create a new project using the androidx-packaged dependencies (as opposed to refactoring an existing project with the Android Studio tool), your new project needs to target API level 28, and you will need to add the following lines to your gradle.properties file: android.useAndroidX=true android.enableJetifier=true требуется выставить targetSdkVersion как минимум 28 и добавить явное разрешение на использование либ из androidx пакета в файле gradle.properties: android.useAndroidX=true android.enableJetifier=true

вторник, 24 декабря 2019 г.

Что такое AndroidX и зачем он?

#android #android_studio #androidx


В окне создания нового проекта появился чекбокс "Use AndroidX artefacts". Почитав
об этом в интернете, я в целом так и не понял, что такое AndroidX. Объясните доступным
языком, пожалуйста. И нужно ли включать его в новых проектах?
    


Ответы

Ответ 1



AndroidX - это новая либа с новым пространством имён на замену support library API. android.support 28.0.0 будет последним. Все что выше будет доступно только через androidx. Поэтому я бы советовал новые проекты сразу переносить или делать на androidX, а вот то что на продакшн как минимум выделить время и потестить. Есть хорошие статьи по этому поводу, как крупные проекты мигрировали и допилвали своими скриптами.

пятница, 7 июня 2019 г.

Добавление зависимости androidx

Файл build.gradle выглядит следующим образом:
apply plugin: 'com.android.application'
android { compileSdkVersion 27 defaultConfig { applicationId "com.example.recyclerviewexample" minSdkVersion 14 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0-beta01' implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01' }
Но в результате сборки ошибки:
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] C:\Users\Xu\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0-beta01.aar\45f296cd7466b0137ad2b0b5868320be
es\values-v28\values-v28.xml Error:(9, 5) error: resource android:attr/dialogCornerRadius not found. C:\Users\Xu\.gradle\caches\transforms-1\files-1.1\appcompat-1.0.0-beta01.aar\45f296cd7466b0137ad2b0b5868320be
es\values\values.xml Error:(1304, 5) error: resource android:attr/fontVariationSettings not found. Error:(1304, 5) error: resource android:attr/ttcIndex not found. D:\Android Projects\RecyclerViewExample\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml Error:(11) error: resource android:attr/dialogCornerRadius not found. Error:(7) resource android:attr/dialogCornerRadius not found. Error:(11) resource android:attr/dialogCornerRadius not found. D:\Android Projects\RecyclerViewExample\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml Error:(231) resource android:attr/fontVariationSettings not found. Error:(231) resource android:attr/ttcIndex not found. Error:failed linking references. Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Execution failed for task ':app:processDebugResources'. > Failed to execute aapt Information:BUILD FAILED in 7s Information:13 errors Information:0 warnings Information:See complete output in console
При этом, если блок dependencies выглядит так:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' }
то сборка проходит успешно. Как добавить зависимость androidx в проект? Версия Android Studio - 3.0.1.


Ответ

Согласно доке
New Project If you create a new project using the androidx-packaged dependencies (as opposed to refactoring an existing project with the Android Studio tool), your new project needs to target API level 28, and you will need to add the following lines to your gradle.properties file: android.useAndroidX=true android.enableJetifier=true
требуется выставить targetSdkVersion как минимум 28 и добавить явное разрешение на использование либ из androidx пакета в файле gradle.properties
android.useAndroidX=true android.enableJetifier=true