amitshekhariitbhu / Fast-Android-Networking

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
https://outcomeschool.com
Apache License 2.0
5.71k stars 960 forks source link

Unable to Build with Latest Android Studio and Kotlin (Duplicate Class) #562

Closed tohizma closed 3 years ago

tohizma commented 3 years ago

I'm using Android Studio 4.2.1 Build #AI-202.7660.26.42.7351085, built on May 11, 2021 Runtime version: 11.0.8+10-b944.6842174 amd64 VM: OpenJDK 64-Bit Server VM by N/A

Kotlin version 1.5.10 (also tried on 1.5.0)

Simple test Code:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        AndroidNetworking.initialize(applicationContext);

        sendToServer("1234")
    }

    private fun sendToServer(scannedCode: String) {

        AndroidNetworking.post("http://192.168.1.3/scanner")
            .addBodyParameter("c", "packinglist")
            .addBodyParameter("d", scannedCode)
            .setTag("scanverify")
            .setPriority(Priority.HIGH)
            .doNotCacheResponse()
            .build()
            .getAsJSONArray(object : JSONArrayRequestListener {
                override fun onResponse(response: JSONArray) {
                    // do anything with response
                    Log.e(TAG, response.toString())
                }

                override fun onError(error: ANError) {
                    // handle error
                }
            })
    }

Build Result:

Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)
     Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-27.1.1-runtime (com.android.support:support-compat:27.1.1)

There's nothing fancy in gradle scripts (except defaults from android studio) and in gradle app module:

implementation 'com.amitshekhar.android:android-networking:1.0.2'

egasudrajat commented 3 years ago

same here

darkbox commented 3 years ago

Add this to the gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

For me it stops complaining

tohizma commented 3 years ago

android.useAndroidX=true

is already there by default

android.enableJetifier=true

Yes! that's solve the problem. Signs that Fast Android Networking library need to be modernized to androidX

Thank you