Programing

API 28 (P) 용 Android 디자인 지원 라이브러리가 작동하지 않음

lottogame 2020. 9. 11. 19:23
반응형

API 28 (P) 용 Android 디자인 지원 라이브러리가 작동하지 않음


android-P SDK 환경을 성공적으로 구성했습니다. Android 디자인 지원 라이브러리를 사용하려고하면 프로젝트 빌드 오류가 발생합니다. 프로젝트 구성은 다음과 같습니다.

IDE : 3.2 Canary 17 대상 API : 28 컴파일 API : 28

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.navigationpoc"
        minSdkVersion 21
        targetSdkVersion 28
        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(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}

빌드 실패 오류는 다음과 같습니다.

매니페스트 병합 실패 : [androidx.core : core : 1.0.0-alpha3] AndroidManifest.xml : 22 : 18-86의 속성 application @ appComponentFactory value = (androidx.core.app.CoreComponentFactory)도 [com.android에 있습니다. .support : support-compat : 28.0.0-alpha3] AndroidManifest.xml : 22 : 18-91 value = (android.support.v4.app.CoreComponentFactory). 제안 : 재정의하려면 AndroidManifest.xml : 6 : 5-40 : 19의 요소에 'tools : replace = "android : appComponentFactory"'를 추가하세요.


이전 API 패키지 버전의 아티팩트 또는 새 Androidx를 사용할 수 있으며 둘 다 사용할 수는 없습니다.

이전 버전을 사용하려면 종속성을

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}

Androidx를 사용하려는 경우 :

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.google.android.material:material:1.0.0-alpha3'
    implementation 'androidx.cardview:cardview:1.0.0-alpha3'
}

중요한 업데이트

Android는 28.0.0.

이것은 android.support 패키징에 따른 마지막 기능 릴리스가 될 것이며 개발자는 AndroidX 1.0.0 으로 마이그레이션하는 것이 좋습니다 .

따라서 AndroidX 라이브러리를 사용 하십시오 .

  • 프로젝트에서 SupportAndroidX모두 사용 하지 마십시오 .
  • 라이브러리 모듈 또는 종속성은 여전히 ​​지원 라이브러리를 가질 수 있습니다. Androidx Jetifier가 처리합니다.
  • Use stable version of androidx or any library, because alpha, beta, rc can have bugs which you dont want to ship with your app.

In your case

dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
}

Add this:

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

to your manifest application

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    tools:replace="android:appComponentFactory"
    android:appComponentFactory="whateverString">

hope it helps


I've used that option:

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

https://developer.android.com/jetpack/androidx/migrate


1.Added these codes to your app/build.gradle:

configurations.all {
   resolutionStrategy.force 'com.android.support:support-v4:26.1.0' // the lib is old dependencies version;       
}

2.Modified sdk and tools version to 28:

compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion  28

2.In your AndroidManifest.xml file, you should add two line:

<application
    android:name=".YourApplication"
    android:appComponentFactory="anystrings be placeholder"
    tools:replace="android:appComponentFactory"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

Thanks for the answer @Carlos Santiago : Android design support library for API 28 (P) not working


Google has introduced new AndroidX dependencies. You need to migrate to AndroidX, it's simple.

I replaced all dependencies to AndroidX dependencies

Old design dependency

implementation 'com.android.support:design:28.0.0'

New AndroidX design dependency

implementation 'com.google.android.material:material:1.0.0-rc01'

you can find AndroidX dependencies here https://developer.android.com/jetpack/androidx/migrate


Automatic AndroidX migration option (supported on android studio 3.3+)

Migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.


open file gradle.properties and add these two lines to it:

android.useAndroidX = true
android.enableJetifier = true

clean and build


I cross that situation by replacing all androidx.* to appropiate package name.

change your line

implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

to

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

NOTED

  • remove tools:replace="android:appComponentFactory" from AndroidManifest

Design support library for androidX is implementation 'com.google.android.material:material:1.0.0'


Note: You should not use the com.android.support and com.google.android.material dependencies in your app at the same time.

to add Material Components for Android

dependencies {
// ...
implementation 'com.google.android.material:material:1.0.0-beta01'
// ...

}

If your app currently depends on the original Design Support Library, you can make use of the Refactor to AndroidX… option provided by Android Studio. Doing so will update your app’s dependencies and code to use the newly packaged androidx and com.google.android.material libraries.

If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.


Below code worked perfectly with me:

dependencies {
    api 'com.android.support:design:28.0.0-alpha3'

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
}

Try this:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

Android documentation is clear on this.Go to the below page.Underneath,there are two columns with names "OLD BUILD ARTIFACT" and "AndroidX build artifact"

https://developer.android.com/jetpack/androidx/migrate

Now you have many dependencies in gradle.Just match those with Androidx build artifacts and replace them in the gradle.

That won't be enough.

Go to your MainActivity (repeat this for all activities) and remove the word AppCompact Activity in the statement "public class MainActivity extends AppCompatActivity " and write the same word again.But this time androidx library gets imported.Until now appcompact support file got imported and used (also, remove that appcompact import statement).

Also,go to your layout file. Suppose you have a constraint layout,then you can notice that the first line constraint layout in xml file have something related to appcompact.So just delete it and write Constraint layout again.But now androidx related constraint layout gets added.

repeat this for as many activities and as many xml layout files..

But don't worry: Android Studio displays all such possible errors while compiling.


The proper fix is as discussed in this answer.

You have to enable jetifier, by adding those two lines to your gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

This will basically exchange the Android Support Library dependencies in your project dependencies with AndroidX-ones.

In case the gradle.properties doesn't exist just create a file called gradle.properties in your root project and add the above-mentioned lines to it:

root
|--gradle.properties
|--build.gradle
|--settings.gradle
|--app
|----build.gradle

Had similar problem. Added in build.gradle and it worked for me.

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

참고URL : https://stackoverflow.com/questions/50782435/android-design-support-library-for-api-28-p-not-working

반응형