capacitor-share-extension icon indicating copy to clipboard operation
capacitor-share-extension copied to clipboard

Potential fix for Android: Cannot find symbol appContext = InstrumentationRegistry.getTargetContext()

Open chanmathew opened this issue 9 months ago • 1 comments

Hi folks,

It appears that the getTargetContext() function is deprecated in Android API level 28, which is causing builds to break. I'm not sure if this effects everyone so I didn't want to create a PR, but here is what I found to resolve it.

Line 22 in ExampleInstrumentedTest.java is the culprit:

Context appContext = InstrumentationRegistry.getTargetContext();

Should be updated to:

Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

This seems to fix the issue for me, here's what I am running: Android studio Jellyfish | 2023.3.1 Android 14 (API level 34) Android Gradle Plugin 8.4.0 Android SDK platform tools 35.0.1 Android emulator 34.2.13

Hope this helps!

chanmathew avatar May 19 '24 17:05 chanmathew