[SOLVED] ThreadLocal.withInitial not found

So I am in still developing phase of my game on Android with min support for sdk 24. Today I tried running my game on avd and was thrown exception "ThreadLocal.withinitial method not found. It was called from jme
Anim.frameintepolator. So I dug up GitHub page to find the line and realise the file was changed two days back. So I looked in Android official docs where I found that withinitial method for threadLocal class was added in Android in api 26. But I want to support api 24-25. Is there any workaround for above exception. I don’t have any knowledge on core engine code.

3 Likes

Please use the latest Android Gradle plugin (AGP) or else enable coreLibraryDesugaring by adding:

dependencies {
    implementation 'com.android.tools:desugar_jdk_libs:2.0.2'
}

and

android {
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Read more in:

and

https://issuetracker.google.com/issues/160484830

Please let us know if the proposed methods above fix your issue.

2 Likes

Firstly Thanks for quick reply.
Okay so it is not working I have tried upgrading gradle to 7.6 ( while desugaring requires min 4). I cannot go gradle beyond this as its throwing error for other android centric libraries I am using like databinding.
I tried all version of desugaring as per this table at bottom Use Java 8 language features and APIs  |  Android Developers
2.0.2 throws upgrade d8 compiler error same with 1.2.2. only 1.1.5 is building module without error but when run on avd same issue.
Nevertheless android 7 seems to be having quite issue as even hardskinning of jme are not working for api24-25. So will not give too much of time for api<26. Despite that if solution is there its more than welcome

1 Like

Note, I mean the AGP version, not the Gradle version. They are different.

For example, try AGP 7.4 (it requires the Minimum required Gradle version 7.5)

1 Like

Yeah but for gradle 7.6 my plugin is 7.2.2 but its still throwing same error.

Please use plugin version 7.4.0 or later.

Using the latest desugar_jdk_libs should most likely solve this. It includs the missing function you mentioned.

See

It requires plugin version 7.4.0 or later as mentioned here:

4 Likes

Yes you are right. It works fine with AGP 7.4.1 and desugaring version 2.0.2 . Nice Thanks a lot !!

4 Likes