CleverTap / clevertap-flutter

CleverTap Flutter SDK
Other
30 stars 42 forks source link

Not possible to add application to AndroidManifest.xml #73

Closed CamronLDNF closed 2 years ago

CamronLDNF commented 2 years ago

I've gone through your Flutter SDK to integrate CleverTap in our Flutter app. Are the instructions up to date? The Android integration section says:

If you do not have an Application class, add this to your AndroidManifest.xml

    <application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:name="com.clevertap.android.sdk.Application"> 

The problem is that it is not possible to do that because I have my default application data there already (and adding the above for CleverTap conflicts and renders an error).

    <application
        android:requestLegacyExternalStorage="true"
        android:name="io.flutter.app.FlutterApplication"
        android:label="Beanie"
        android:icon="@mipmap/ic_launcher">

What is the solution here? The AndroidManifest.xml file in your example code does not reflect the above instructions.

darshanclevertap commented 2 years ago

@CamronLDNF If you have a custom application class, call ActivityLifecycleCallback.register(this); before super.onCreate() in your class.

We're in the process of upgrading our Flutter documentation. We'll add this there as well. 👍🏾

CamronLDNF commented 2 years ago

@darshanclevertap about this:

@CamronLDNF If you have a custom application class, call ActivityLifecycleCallback.register(this); before super.onCreate() in your class.

That is already stated in your documentation. I don't have a custom application class though, so that is why I instead followed the instructions on If you do not have an Application class.... But I'm getting aforementioned error. What do I do?

darshanclevertap commented 2 years ago

@CamronLDNF Please create an Application class in your Android project and extend it from FlutterApplication class and then do the following -

If you have a custom application class, call ActivityLifecycleCallback.register(this); before super.onCreate() in your class.

We need this to correctly track App launches, FCM tokens, render InApp Notifications and other session-related stuff.

CamronLDNF commented 2 years ago

@darshanclevertap the solution was actually much simpler (or so it seems). Your documentation states:

If you do not have an Application class, add this to your AndroidManifest.xml

The word "add" in your instructions is what through me off. Apparently there can be only one android:name attribute, which is the class that is instantiated before any of the application's components. Instead of adding, I replaced android:name="io.flutter.app.FlutterApplication" with android:name="com.clevertap.android.sdk.Application" and now it works. Like this:

<application
    android:requestLegacyExternalStorage="true"
    android:name="com.clevertap.android.sdk.Application" 
    android:label="Beanie"
    android:icon="@mipmap/ic_launcher">

So now when the app is started, this CleverTap custom class is instantiated before any of the application's components.

I think this should be clarified in your Flutter documentation.