How to debug android SDK classes? - android

I want to check why sometimes my invalidate() not call onDraw.
1 step: I set a breakpoint on invalidate().
2 step: I click "Step Into" button (also tried "Force Step Into"). But debugger goes not inside invalidate(). It goes inside getElevation() instead. Why?
picture 1
Also, I tried to set a breakpoint inside invalidate() method of View class on line invalidate(true);. But it also remains unreachable. It says that "No executable code ...".
picture 2

I solved it partially.
Device version must be the same as SDK sources version, compileSdkVersion, buildToolsVersion, targetSdkVersion.
In my case SDK sources API 24.
build.gradle:
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
targetSdkVersion 24
...
}
Tracing now works (with these parameters only on API 24 device) but breakpoints still don't work (same No executable code error).

You can try to download the Sources for Android SDK for your targetSdkVersion inside build.gradle and see if you can debug inside the methods then.
But note that the newest Android API 25 does not have the sources available yet.

Related

Is it safe to target sdk version 33 (Android 13)?

So I have seen that Android 13 has been officially released. But, when I searched for it in the official page, I have seen that it appears as beta version: https://developer.android.com/studio/releases/platforms#13
So, my question is, is it better to wait some time so that it is safe to target that Android 13 version?
I would say - it depends on your app, but mostly sure, it's safe. For example, we faced a couple of issues with the notification permission and a foreground service and it took some time to fix and test it, and it's always better to test such things on a real device rather than an emulator with a strange behaviour coming from the newest system image. If you don't have any particular/hardware places which should be tested on a physical device only, then I think that it's safe enough - you'll have plenty of time to fix any random roughnesses :)
Yes it is safe, Mine is given below in android/build
.gradle
ext {
buildToolsVersion = "33.0.1"
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 33
androidXCore = "1.6.0"
kotlinVersion = "1.6.0"
}

"Unsupported value: Tiramisu" while I try to set up the Android 13 SDK

I followed this page: https://developer.android.com/about/versions/13/setup-sdk
to set up Android 13 SDK.
In my build.gradle:
android {
compileSdkVersion("Tiramisu")
defaultConfig {
targetSdkVersion("Tiramisu")
}
}
Then I got the error:
> Unsupported value: Tiramisu. Format must be one of:
- android-31
- android-31-ext2
- android-T
- vendorName:addonName:31
I tried to use "33" instead of "Tiramisu", but it's not working.
I'm using the latest Android Studio Preview as the instruction.
Is there anyone trying to use Android 13 SDK?
This answer is no longer valid because you can use API version 33 now for Tiramisu as it's officially released
Credit to #NickolaySavchenko - Posting this answer since I've been waiting for him for a day.
Finally, after taking advice from #NickolaySavchenko - I have a final working code like this.
compileSdkVersion "android-Tiramisu"
targetSdkVersion "Tiramisu"
Yes, you see it correctly, the targetSdkVersion is Tiramisu, not android-Tiramisu so that it can run in an emulator API Tiramisu device.
I tested and can confirm that minSdkVersion doesn't need to change to android-Tiramisu or Tiramisu. I'm still keeping it as 19 and it's working great.
As #NickolaySavchenko said
compileSdkPreview "android-Tiramisu"
targetSdkPreview "android-Tiramisu"
working fine
and to run it on android 13 you also need to change your minSdk to "android-Tiramisu"

No virtual method getLongVersionCode()J when getting version code

According google suggestion i am using getLongVersionCode to get version code like this:
private long getCurrentCode() {
try {
return context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0).getLongVersionCode();
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
but when i run my app, my app force closed and i got this error:
Process: com.xxxxx.debug, PID: 25754
java.lang.NoSuchMethodError: No virtual method getLongVersionCode()J in class Landroid/content/pm/PackageInfo; or its super classes (declaration of 'android.content.pm.PackageInfo' appears in /system/framework/framework.jar)
at com.xxxxx.common.ApplicationUpdateTask.getCurrentCode(ApplicationUpdateTask.java:329)
at com.xxxxx.common.ApplicationUpdateTask.<init>(ApplicationUpdateTask.java:84)
So i decided to use:
String versionName = BuildConfig.VERSION_NAME;
but now this commend return -1 !!!!!
This is my gradle config:
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 66
versionName '2.0.66'
applicationId 'com.xxxxxx.yyyyy'
multiDexEnabled true
}
I recommend you to use PackageInfoCompat:
PackageInfoCompat.getLongVersionCode();
It automatically checks the sdk version greater than 28 and returns appropriately versionCode or LongVersionCode. It is included in androidx.
The method long getLongVersionCode() was added to Android in version 28; see javadoc
It is clearly present in the APIs you are compiling against, otherwise you would get a compilation error.
But the exception says that it is not present at runtime, so you must have been running on an older platform.
I don't know what you mean when you say that you used this:
String versionName = BuildConfig.VERSION_NAME;
The version name and code are different things. Maybe you used BuildConfig.VERSION_CODE?
And I don't know what you mean by this:
but now this commend return -1 !!!!!
My guess is that there is something wrong with way you are using the version name or code attributes. But that's just a guess. You haven't shown us the code.
The other thing to note is that prior to API version 28, you could use the PackageInfo.versionCode attribute (javadoc). This was deprecated in API version 28. So it should be possible to use reflection to call the getLongVersionCode() method if available, and fall back to using reflection to access the versionCode attribute. (Or test the value of Build.VERSION.SDK_INT at runtime to find out what API version the platform supports.)
Or you could just set the minimum supported Android version for your app to 28.
Just a note for those looking here. Although this says that it was added in 28, I can say for sure it does not work in Android 8.1. Same runtime error. Changing my code to check for Android.os.Build.VERSION_SDK_INT >= Build.VERSION_CODES.P before trying to use getLongVersionCode() avoided the error.

Yazeed44 MultiImagePicker not working

I was trying to implement the MultiImagePicker from Yazeed44 (https://github.com/yazeed44/MultiImagePicker).
The problem I have is, when I open the image selector:
new Picker.Builder(getActivity(), new MyPickListener(), R.style.MIP_theme)
.build()
.startActivity();
The view remains empty where it should be displaying the photo albums to select from. See the screenshot:
What am I missing in order to get this to work?
I'm testing with a Google Nexus 6P with Android 6.0.1. minSdkVersion 19, targetSdkVersion 23. And I'm Gradle importing: net.yazeed44.imagepicker:imagepicker:1.3.0
Try to set targetSdkVersion to 22, the problem occurs because in android 6 you need to request for permissions at run-time. If you have configured targetSdkVersion to 23 in your project, your app needs to support Runtime Permission, but if you doesn't have your code prepared to manage this, you neeed to change targetSdkVersion to 22, in this way you are going to get de old permission behavior.
"Warning: Right now when you create a new project in Android Studio.
targetSdkVersion will be automatically set to the latest version, 23.
If you are not ready to make your application fully support the
Runtime Permission, I suggest you to step down the targetSdkVersion to
22 first."
https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

Android Requires MinSdk <=9

When I am trying to make a new Google Maps Activity, its grey and I cant click the option. (New --> Google --> Google Maps Activity (Requires MinSdk >=9)
I got the same message when I create a new app and try to choose the activity while setting up a new project.
C:\Users\Joey\AppData\Local\Android\sdk\platforms
Android-23
And when opening the SDK manager in Android Studio I got the following SDK tools.
Can someone tell me if Im missing something?
In your application level build.gradle file do you have minSdkVersion 9 or greater than 9 like this:
defaultConfig {
minSdkVersion 15 //this should be greater than or equal to 9
targetSdkVersion 23
//...
}

Categories

Resources