amplitude / Amplitude-Android

Native Android SDK for Amplitude
MIT License
162 stars 90 forks source link

Where is Constants.DEFAULT_INSTANCE substituted with the actual value? #326

Closed mblarsen closed 2 years ago

mblarsen commented 2 years ago

Summary

The database name is based on Constants.DEFAULT_INSTANCE

https://github.com/amplitude/Amplitude-Android/blob/d97b951891da5bdc8e5766c7ecd04272f0148923/src/main/java/com/amplitude/api/DatabaseHelper.java#L71-L83

But the value is just

https://github.com/amplitude/Amplitude-Android/blob/d97b951891da5bdc8e5766c7ecd04272f0148923/src/main/java/com/amplitude/api/Constants.java#L23

Where is $default_instance substituted by a proper name?

mblarsen commented 2 years ago

Sorry, missed it.

Defined here:

https://github.com/amplitude/Amplitude-Android/blob/d97b951891da5bdc8e5766c7ecd04272f0148923/src/main/java/com/amplitude/api/DatabaseHelper.java#L71-L73

Defaults to the package name + instance id / api key

mblarsen commented 2 years ago

I have this really odd case where the Amplitude database changed its name from one version to the other.

From the looks of it in my old app version the name was generated in a manner that seems impossible if you read the amplitude/Android source code.

(old file name)

%40plantura%2Fapp-com.amplitude.api_XXXXXXXXXXX

Note: %40plantura%2Fapp is @plantura/app

(new file name; and correct) com.amplitude.api_XXXXXXXXXXX

How could the old file name possibly be named like that. There is no code whatsoever that explicitly tries to set the database name. There is no API from amplitude/Android that allows to add a prefix to the DATABASE_NAME.

The normalized database name is passed to Androids Context API getDatabasePath(dbname) so the only way would be to change the context somehow. That doesn't happen in the expo module as well.

amplitude-db-name

bohan-amplitude commented 2 years ago

Hi @mblarsen ,

Thank you for your info. What version is the old version you mentioned?

mblarsen commented 2 years ago

Hi @mblarsen ,

Thank you for your info. What version is the old version you mentioned?

Hi @bohan-amplitude

So the version that has the seemingly impossible database prefix is Expo SDK 42 and Amplitude version 2.23.2 included through expo-analytics-amplitude version 10.2.0 and my app version 2.4.

The version with the expected prefix is Expo SDK 44, same Amplitude version but included through expo-analytics-amplitude version 11.1.0 and my version 2.5

So from expo-analytics-amplitude 10.2 to 11.1 which includes the identical version of amplitude/Android we lose all Amplitude users (100k+) because the underlying database name is "fixed".

Unfortunate but even more mind boggling how it could have been named @owner/app-com.amplitude_apikey in the first place.