line/line-sdk-android

An error will occur in the build. What kind of cause can be considered?

Closed this issue · 7 comments

The following error occurs at build time.
What kind of cause can be considered?
I succeeded in building the example application of this repository.
SDK Version is 5.0.1

Error:Exception in thread "main" java.lang.IllegalStateException: Expected a load for Landroid/view/View$OnClickListener; to set up parameter 1 for com/linecorp/linesdk/widget/LoginButton$$Lambda$3 but got -1
	at com.google.common.base.Preconditions.checkState(Preconditions.java:756)
	at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.attemptAllocationBeforeArgumentLoads(LambdaDesugaring.java:543)
	at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:427)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1623)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
	at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
	at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
	at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
	at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

FAILURE: Build failed with an exception.

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.example.xxxxx.linelogintest"
        minSdkVersion 23
        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'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation('com.madgag.spongycastle:prov:1.58.0.0')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation(name:'line-sdk-5.0.1', ext:'aar')
    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'
}

The same error occurs for me.

What's the problem?

We used lambda in LINE SDK, but looks like your development environment(Android Studio 3.1 or newer?) does not support lambda.

Please try the following:

  1. create a gradle.properties file in your project root path
  2. add the following setting in this file:
    android.enableD8.desugaring=true

We added the same setting in this repo, that's why our sample application and LINE SDK itself could be compiled.

Please refer to this article for more detail: Android Studio Switched to New D8 Compiler

thank you!

This issue still exists after I add the android.enableD8.desugaring=true in my gradle.properties file.

app/build.gradle

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        ...
        minSdkVersion 17
        targetSdkVersion 27
        ...
    }
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == 'com.android.support') {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion '27.1.1'
                }
            }
        }
    }
}

dependencies {
    ...
    implementation(name:'line-sdk-5.0.1', ext:'aar')
    implementation('com.madgag.spongycastle:prov:1.58.0.0') {
        exclude group: 'junit', module: 'junit'
    }

    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
    runtimeOnly ('io.jsonwebtoken:jjwt-orgjson:0.10.5') {
        exclude group: 'org.json', module: 'json' //provided by Android natively
    }
}

It works fine after I update com.android.tools.build:gradle.

classpath 'com.android.tools.build:gradle:3.1.2' is the version of this rep uses.

I've also had this issue (but unrelated to this repo), and the fix was the team providing the aar library compiled the library using the same gradle version that we compile our application, and that library worked.

For reference only, lamda is terrible for code maintenance. ' _ '