GabrielBB / Android-CutOut

Android image background removing library
Other
265 stars 90 forks source link

NoSuchMethodError when trying to use CutOut #24

Closed Zaphelyn closed 4 years ago

Zaphelyn commented 4 years ago

Hello Gabriel,

First I would just like to say thanks for developing this, I have a number of different projects that I would like to incorporate CutOut into, but I'm getting an issue whenever I try to start the CutOut activity. Any help I could get in making this work with my project would be awesome, and I would appreciate it.

My error output:

2020-10-29 15:42:33.510 26017-26017/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.backgroundremovalexample, PID: 26017 java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar) at com.github.gabrielbb.cutout.CutOutActivity.setUndoRedo(CutOutActivity.java:298) at com.github.gabrielbb.cutout.CutOutActivity.onCreate(CutOutActivity.java:116) at android.app.Activity.performCreate(Activity.java:8000) at android.app.Activity.performCreate(Activity.java:7984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

My MainActivity.java:

package com.example.backgroundremovalexample;

import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button;

import com.github.gabrielbb.cutout.CutOut;

public class MainActivity extends AppCompatActivity {

private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = findViewById(R.id.button_start_cutout);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri uri = Uri.parse("/sdcard/Download/21110378192_ccd70526ed_o.jpg");

            CutOut.activity().src(uri).intro().start(MainActivity.this);

        }
    });

My Gradle file (app):

apply plugin: 'com.android.application'

android { compileSdkVersion 30 buildToolsVersion "30.0.2"

defaultConfig {
    applicationId "com.example.backgroundremovalexample"
    minSdkVersion 22
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

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

}

dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'com.github.gabrielbb:cutout:0.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

My Gradle file (Project):

/ 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:4.0.2"

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

}

allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } } }

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

Thanks for any guidance you can give me! Look forward to hearing from you.

-Zaphelyn

Zaphelyn commented 4 years ago

Was able to fix this and run the code correctly by adding:

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

to my app level build.gradle file. Closing 10/30/2020.

-Zaphelyn