ttlock / Android_SDK_Demo

TTLock is a global provider of solutions for smart locks. We provide PCBA and softwares for lock manufactures and end users. We provide open API/SDK for developers. With these APIs/SDKs, you can develop your own applications to manage smart locks. The SDK here is for mobile app to communicate with locks via bluetooth.
23 stars 24 forks source link

ArrayIndexOutOfBounds Exception after ControlLock #8

Open franciscorosso opened 4 years ago

franciscorosso commented 4 years ago

Hello everyone,

After using the method controlLock, an exception is thrown that freezes my UI, I dont know how to handle it in order to make my app work. It happens with just few phones.

The error is throwing from the SDK. Here the stacktrace.

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0 at android.util.SparseArray.keyAt(SparseArray.java:295) at com.ttlock.bl.sdk.api.j.f(Unknown Source:76) at com.ttlock.bl.sdk.api.a$5.run(Unknown Source:1534) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7520) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Thanks in advance, Francisco.

indrian16 commented 4 years ago

The crash occurred on Android 10 ?, if yes we have the same problem

franciscorosso commented 4 years ago

The crash occurred on Android 10 ?, if yes we have the same problem

Finally I made it work. Set in build.gradle targetSdkVersion 28 and compileSdkVersion 28. It will work for Android 10 too, but in the future TTLock will have to fix it to use sdk 29.

LCheongYu0316 commented 3 years ago

Now that builds targeting SDK 28 are no longer allowed to be uploaded to Play Store, has anyone found a solution or workaround for this while targeting SDK higher than 28?

franciscorosso commented 3 years ago

Now that builds targeting SDK 28 are no longer allowed to be uploaded to Play Store, has anyone found a solution or workaround for this while targeting SDK higher than 28?

Have you tried updating the version of TTLock? Go to build.gradle and modify it to 3.1.1 and build the project again so it downloads the new version.

https://repo.gradle.org/gradle/repo/com/tongtonglock/ttlock/

There you can see there were new releases of the SDK.

If it works, please let me know!

LCheongYu0316 commented 3 years ago

iirc the same problem happened with TTLock SDK 3.0.6 which worked when I targeted Android SDK 28. My gradle has minifyEnabled, shrinkResources, useProguard set to false. Trying every version between 3.0.6 and 3.1.1 then, doubt anything fruitful will happen.

franciscorosso commented 3 years ago

I am in the same situation, I have my app without updating just because of this, but I hadn’t tried the new versions of the SDK. I hope they fix it soon.

LCheongYu0316 commented 3 years ago

@franciscorosso Well turns out it was my own problem, because my build process involves [Project JAR] building a .jar file that contains the code that actually practically uses TTLock SDK, then include this .jar into my [Project App] project folder before building. As I haven't been updating dependencies of TTLock SDK and the codes in [Project JAR], the upgrade produced a problem due to different parameters in the interface ControlLockCallback. Due to the setup above it obfuscated the source of error.

TL;DR, TTLock SDK 3.1.1 works while targeting Android SDK 29. Haven't tried Android SDK 30 but I suppose it should be okay.

P.S. can you delete the comment above quoting my error message since I hastily left my package name there. Edit history is public so I will delete mine too after you. Sorry for the trouble.

franciscorosso commented 3 years ago

@franciscorosso Well turns out it was my own problem, because my build process involves [Project JAR] building a .jar file that contains the code that actually practically uses TTLock SDK, then include this .jar into my [Project App] project folder before building. As I haven't been updating dependencies of TTLock SDK and the codes in [Project JAR], the upgrade produced a problem due to different parameters in the interface ControlLockCallback. Due to the setup above it obfuscated the source of error.

TL;DR, TTLock SDK 3.1.1 works while targeting Android SDK 29. Haven't tried Android SDK 30 but I suppose it should be okay.

P.S. can you delete the comment above quoting my error message since I hastily left my package name there. Edit history is public so I will delete mine too after you. Sorry for the trouble.

Great man! Thanks for sharing the solution.

PS I deleted my previous message. So everything ok.

Greetings, Francisco

LCheongYu0316 commented 3 years ago

Thanks a lot too.