3

I'm making app with the chrome custom tabs. When I try run app on Lollipop, I get error:

Error: Static interface methods are only supported starting with Android N (--min-api 24): androidx.browser.trusted.TrustedWebActivityDisplayMode androidx.browser.trusted.TrustedWebActivityDisplayMode.fromBundle(android.os.Bundle)

How can I fix it?

My gradle app module:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"


    defaultConfig {
        applicationId "com.myapp.news"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    dynamicFeatures = [":features", ":customlist"]


}

dependencies {

    //### Base
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    api 'androidx.appcompat:appcompat:1.1.0'
    api 'androidx.core:core-ktx:1.2.0'
    api 'androidx.legacy:legacy-support-v4:1.0.0'
    api "androidx.annotation:annotation:1.1.0"

    // Install: Dynamic Module
    api("com.google.android.play:core:1.7.2")

    // lifecycle & ViewModel
    api 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    api 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    // Navigation
    api "androidx.navigation:navigation-fragment-ktx:2.3.0-alpha05"
    api "androidx.navigation:navigation-ui-ktx:2.3.0-alpha05"
    api "androidx.navigation:navigation-dynamic-features-fragment:2.3.0-alpha05"


    // Preference
    api "androidx.preference:preference-ktx:1.1.1"

    // Database
    api 'androidx.room:room-runtime:2.2.5'
    kapt "androidx.room:room-compiler:2.2.5"
    // optional - Kotlin Extensions and Coroutines support for Room
    api "androidx.room:room-ktx:2.2.5"

    //### Layouts & Design
    api 'com.google.android.material:material:1.1.0'
    api 'androidx.constraintlayout:constraintlayout:1.1.3'
    // Recyclerview
    api 'androidx.recyclerview:recyclerview:1.1.0'
    api 'androidx.recyclerview:recyclerview-selection:1.0.0'
    // Drawer
    api 'com.mikepenz:materialdrawer:8.0.0-rc01'
    api "com.mikepenz:materialdrawer-nav:8.0.0-rc01"


    // Anko Commons
    implementation "org.jetbrains.anko:anko-commons:0.10.8"

    // Custom Tab Chrome
    implementation "androidx.browser:browser:1.2.0"

    //### Tests
    implementation 'androidx.preference:preference:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


}

but it doesn't help.

I use chrome tabs in Navigator (Navigation components ).


@Navigator.Name("chrome")
class ChromeCustomTabsNavigator(private val context: Context) : Navigator<ChromeCustomTabsNavigator.Destination>() {

    override fun createDestination()= Destination(this)

    override fun navigate(destination: Destination, args: Bundle?, navOptions: NavOptions?, navigatorExtras: Extras?): NavDestination? {

        val url = args?.getString("url") ?: throw IllegalStateException("Destination ${destination.id} does not have an url.")

        if (url.isInvalidWebUrl()) {
            throw IllegalArgumentException("Url($url) is a invalid web URL.")
        }

        val customTabChrome = CustomTabsIntent.Builder()

        val intent = customTabChrome.build()
        try {
            intent.launchUrl(context, Uri.parse(url))
        } catch (e: ActivityNotFoundException) {
            throw e
        }
        return null // Do not add to the back stack, managed by Chrome Custom Tabs
    }

    override fun popBackStack() = true // Managed by Chrome Custom Tabs

    @NavDestination.ClassType(Activity::class)
    class Destination(navigator: Navigator<out NavDestination>) : NavDestination(navigator)

    private fun String.isInvalidWebUrl(): Boolean {
        return Patterns.WEB_URL.matcher(this).matches().not()
    }

}

Thanks for help :)

mmaciejow
  • 57
  • 7
  • This looks like a duplicate of this: https://stackoverflow.com/questions/49512629/default-interface-methods-are-only-supported-starting-with-android-n and this https://stackoverflow.com/questions/53402639/static-interface-methods-are-only-supported-starting-with-android-n-min-api-2/53406307 Can you check if the `compileOptions` are correctly put inside the `android` section? – andreban Apr 30 '20 at 11:51
  • @andreban as I wrote above: **compileOptions** doesn't work :( – mmaciejow Apr 30 '20 at 12:50
  • Can you post the entire app/build.gradle? – andreban Apr 30 '20 at 18:45

0 Answers0