Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.VerifyError: Verifier rejected class #17

Closed
siddhpuraamitr opened this issue Dec 8, 2020 · 9 comments
Closed

java.lang.VerifyError: Verifier rejected class #17

siddhpuraamitr opened this issue Dec 8, 2020 · 9 comments

Comments

@siddhpuraamitr
Copy link

siddhpuraamitr commented Dec 8, 2020

I don't want to use callback, for that I am using suspendCancellableCoroutine,
Below function, I have used to get deviceId

        val fingerprinted = FingerprinterFactory
           .getInstance(activity, Configuration(version = 1))

       val deviceId = suspendCancellableCoroutine<String> {
           try {
               fingerprinted.getDeviceId { result ->
                   val deviceId = result.deviceId
                   it.resume(deviceId)
               }
           }catch (e: Exception){
               it.resumeWithException(e)
           }
           it.cancel()
       }

I am always getting an error like below

Process: com.account, PID: 19905
    java.lang.VerifyError: Verifier rejected class com.account.DeviceManager: java.lang.Object com.account.DeviceManager.getDeviceId(android.content.Context, kotlin.coroutines.Continuation) failed to verify: java.lang.Object com.account.DeviceManager.getDeviceId(android.content.Context, kotlin.coroutines.Continuation): [0x1A] register v1 has type Reference: android.content.Context but expected Precise Reference: com.account.DeviceManager (declaration of 'com.account.DeviceManager' appears in /data/app/com.account-cYswagkBsh_1A8mtjV9kYg==/base.apk!classes4.dex)
    
@Alexey-Verkhovsky
Copy link
Member

Alexey-Verkhovsky commented Dec 8, 2020

Hi!
I tried to reproduce the issue, and the following code works fine:

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

    textView = findViewById(R.id.text)

    val fingerprinter = FingerprinterFactory.getInstance(applicationContext, Configuration(version = 1))


    runBlocking {
        updateView(suspendCancellableCoroutine { continuation ->
            try {
                fingerprinter.getDeviceId {
                    continuation.resume(it) {}
                }
            } catch (e: Exception) {
                
            }
        })
    }
}

private fun updateView(it: DeviceIdResult) {
    runOnUiThread {
        textView?.text = it.deviceId
    }
}

Have you tried to clean the project? Invalidate cache/Restart in Android Studio?

@siddhpuraamitr
Copy link
Author

siddhpuraamitr commented Dec 9, 2020

Don't know, why I am getting same error again and again,

If I use it without Coroutine it is working fine!!

Tried, Invalidate Cache/ Restart, Rebuild, Reinstall App, Different Phone.

My configuration is

        minSdkVersion 24
        targetSdkVersion 29

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
    dexOptions {
        incremental = true
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }

     /** Kotlin **/
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.21'

    /** Kotlin Coroutine **/
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3'

 ext.compileSdkVersion = 29
    ext.buildToolsVersion = "29.0.3"
    ext.kotlin_version = '1.4.21'
    ext.gradle_version = '4.1.1'
    ext.releaseDate = '18 May 2020'

    apply from: 'gradle/dependencies.gradle'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven.google.com"}
    }

    dependencies {
        classpath "com.android.tools.build:gradle:${gradle_version}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

@Alexey-Verkhovsky
Copy link
Member

Alexey-Verkhovsky commented Dec 9, 2020

I've found an issue, and the error is very similar. That one happened because of the bug in the compiler in version 1.3.6. Yours is 1.3.3, but probably this is another one. I tried to reproduce it with my simple application and it's still working fine. Maybe the problem reproduces only with more complex classes and nested coroutines as you have.

Let's try to localize the problem and perform a few experiments:

  1. What if you change your code to the following, will it still be crashing? I just removed all the code with fingerprinter to check for problems with coroutines.

     val fingerprinted = FingerprinterFactory
        .getInstance(activity, Configuration(version = 1))
    
    val deviceId = suspendCancellableCoroutine<String> {
        try {
            Thread().run {
                     it.resume("")
             }
        }catch (e: Exception){
            it.resumeWithException(e)
        }
        it.cancel()
    }
    
  2. What if you remove try/catch construction?

     val fingerprinted = FingerprinterFactory
        .getInstance(activity, Configuration(version = 1))
    
    val deviceId = suspendCancellableCoroutine<String> {
        fingerprinted.getDeviceId { result ->
                val deviceId = result.deviceId
                it.resume(deviceId)
        }
        it.cancel()
    }
    
  3. What if you remove it.cancel()?

  4. Another option is to update the coroutine library from 1.3.3 to 1.3.6. If it won't help then update to 1.4.0 and check for the result again.

@siddhpuraamitr
Copy link
Author

Hi thank you so much for your support.

Mainly I need device Id so I have used below function

val deviceId = GsfIdProvider(activity.contentResolver).getGsfAndroidId() ?: AndroidIdProvider(activity.contentResolver!!).getAndroidId()
Now it is working fine for me.

@Alexey-Verkhovsky
Copy link
Member

You are welcome!

It's better to use getDeviceId method, because it may contain an additional logic in the future, and internals may be unavailable, so consider to investigate the issue when you have time.

@siddhpuraamitr
Copy link
Author

Hi, Alexey, I have used below code as per your suggestion

val fingerprinted = FingerprinterFactory
           .getInstance(activity, Configuration(version = 1))

       val deviceId = suspendCancellableCoroutine<String> { it ->
           try {
               Thread().run {
                   fingerprinted.getDeviceId { deviceIdResult ->
                       it.resume(deviceIdResult.deviceId)
                   }

               }
           } catch (e: Exception) {
               it.resumeWithException(e)
           }
           it.cancel()
       }

But still application is crashing same way.

I have also tried without try, catch block, but still I am getting same error

Again thank you so much for your till support.

Let me know if I can help you in any test cases. Thanks alot

@Alexey-Verkhovsky
Copy link
Member

Alexey-Verkhovsky commented Dec 11, 2020

I am not very familiar with Kotlin coroutines, but there is a problem in your code.
it.cancel executes earlier than it.resume, and that leads to crash in my simple application. That's because it.resume() executes asynchronously, and it.cancel - synchronously. Try to remove it.cancel(), it's redundant here.

Also check for usage example in the official docs.

@Alexey-Verkhovsky
Copy link
Member

I close the issue because there is a problem in the code, and there is no new information. When new information is received, we will re-open it.

@siddhpuraamitr
Copy link
Author

Ok, no issue, thanks for your continue support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants