Android Question NonSdkApiUsedViolation

CaptKronos

Active Member
Licensed User
Just noticed that Google's Pre-Launch Report for my app has raised a "Usage of non SDK interfaces" issue when testing against an Android 9 device.

The logcat has recorded many instances of the violation with the following being an example chosen at random.

B4X:
37315 09-27 10:53:49.854: D/StrictMode(12541): StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/WindowManagerGlobal;->mViews:Ljava/util/ArrayList;
37316 09-27 10:53:49.854: D/StrictMode(12541):     at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
37317 09-27 10:53:49.854: D/StrictMode(12541):     at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
37318 09-27 10:53:49.854: D/StrictMode(12541):     at java.lang.Class.getDeclaredField(Native Method)
37319 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.base.RootsOracle.a(RootsOracle.java:13)
37320 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.base.RootViewPicker$RootResultFetcher.a(RootViewPicker.java:5)
37321 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.base.RootViewPicker.a(RootViewPicker.java:37)
37322 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:10)
37323 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.base.ViewFinderImpl.a(ViewFinderImpl.java:10)
37324 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:58)
37325 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:94)
37326 09-27 10:53:49.854: D/StrictMode(12541):     at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
37327 09-27 10:53:49.854: D/StrictMode(12541):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
37328 09-27 10:53:49.854: D/StrictMode(12541):     at android.os.Handler.handleCallback(Handler.java:873)
37329 09-27 10:53:49.854: D/StrictMode(12541):     at android.os.Handler.dispatchMessage(Handler.java:99)
37330 09-27 10:53:49.854: D/StrictMode(12541):     at android.os.Looper.loop(Looper.java:193)
37331 09-27 10:53:49.854: D/StrictMode(12541):     at android.app.ActivityThread.main(ActivityThread.java:6669)
37332 09-27 10:53:49.854: D/StrictMode(12541):     at java.lang.reflect.Method.invoke(Native Method)
37333 09-27 10:53:49.854: D/StrictMode(12541):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
37334 09-27 10:53:49.854: D/StrictMode(12541):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Would I be correct in assuming that this issue is due to the code that B4A generates rather than what I have written? And hence it will be fixed in a future version of B4A?
 

CaptKronos

Active Member
Licensed User
From the logcat I have no idea what code is causing the issues. As far as I can see the enforcement of the violation has been introduced with Android 9 (API 28). I'll follow the advice presented here:

https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces

My post was really just a heads up on what seems to be changing rather than expecting anyone to debug my code. If no one else has been impacted by the Android 9 change, then it must be something at my end.
 

DonManfred

Expert
Licensed User
How can I detect non-SDK interface uses when my app is running?

A logcat warning is printed of the form Accessing hidden field|method .... In addition, toast messages are shown for debuggable apps, and logcat messages are printed for any non-SDK interfaces that are denied.

So you´ll probably get more infos in the unfiltered log.
 

CaptKronos

Active Member
Licensed User
I have been testing using the emulator running API 28 and I can't see any NonSdkApiUsedViolation syslog messages. (I'm using Android Studio's viewer.) I thought it might be because StrictMode had to be explicitly set so I used Informatix's StrictMode lib to do so. I saw the usual StrictMode "noise" but still no NonSdkApiUsedViolation messages. Is there a particular API 28 image that I need to use? The Android Developer docs seem to suggest any API 28 image should work.
 

Erel

Administrator
Staff member
Licensed User
It is probably not a real issue. Check the unfiltered logs when you run your app on an Android 9 device. You should see a message about the restricted access. If it is marked as "light-gray" then it is fine.
 

CaptKronos

Active Member
Licensed User
Thanks. Unfortunately I don't have an Android 9 device but once I do I'll follow your suggestion. In the mean time I won't worry too much about it.
 

CaptKronos

Active Member
Licensed User
In which case I am confused again since, as I said in yesterday's post, when testing with the emulator I couldn't get any NonSdkApiUsedViolation messages to appear in the syslog. However, I still won't worry about it.
 

Erel

Administrator
Staff member
Licensed User
Have you checked the unfiltered logs? It is easy to miss those messages.

You can see the message if you call Msgbox or DoEvents.
 

CaptKronos

Active Member
Licensed User
I have created a project with just
B4X:
Sub Button1_Click
    For i=0 To 10
        DoEvents
    Next
    Msgbox("hello", "title")
End Sub
and I still don't see any messages referring to NonSdkApiUsedViolation. Filter is definitely off.
 

Erel

Administrator
Staff member
Licensed User
I confirm. The messages only appear on the real device.

They look like:
Accessing hidden method Landroid/os/MessageQueue;->next()Landroid/os/Message; (light greylist, reflection)
 
Top