1

I have been trying to add Apple MusicKit auth SDK to an android app, I have added the AAR provided by apple and the necessary step to initialize the auth flow, but the SDK just redirects me to the google play store listing of apple music, I do have the app installed and logged in on my test device.

Apple MusicKit Auth SDK : musickitauth-release-1.1.2.aar

Here's the piece of code I use to init the auth flow :

val intent = authenticationManager.createIntentBuilder(BuildConfig.APPLE_DEV_TOKEN)
    .setHideStartScreen(true)
    .setStartScreenMessage("Connect with Apple Music")
    .build()

startActivityForResult(intent , Const.APPLE_REQ_CODE)

Here's the ActivityRequest Code :

val result = authenticationManager.handleTokenResult(data)

if (result.isError) {
    val error = result.error
    Alerts.log(TAG , "APPLE ERROR: $error")
}
else {
    Alerts.log(TAG , "APPLE TOKEN: ${result.musicUserToken}")
}

This is what I get in my logs :

D/SDKUriHandlerActivity: onCreate: DEV_TOKEN_HERE
D/AuthUtils: deeplinkAppleMusic: uri = musicsdk://applemusic/authenticate-v1?appPackage=PACKAGE_ID&devToken=DEV_TOKEN_HERE
W/System.err: android.content.pm.PackageManager$NameNotFoundException: com.apple.android.music
W/System.err:     at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:244)
W/System.err:     at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:213)
W/System.err:     at com.apple.android.sdk.authentication.a.a(AuthSDK:92)
W/System.err:     at com.apple.android.sdk.authentication.a.b(AuthSDK:66)
W/System.err:     at com.apple.android.sdk.authentication.a.b(AuthSDK:56)
W/System.err:     at com.apple.android.sdk.authentication.SDKUriHandlerActivity.onCreate(AuthSDK:43)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8183)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8167)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1316)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3751)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3950)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2377)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:262)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:8304)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
D/a: deeplinkAppleMusic: isAppleMusicInstalled(activity) = 2
W/System.err: android.content.pm.PackageManager$NameNotFoundException: com.apple.android.music
W/System.err:     at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:244)
W/System.err:     at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:213)
W/System.err:     at com.apple.android.sdk.authentication.a.a(AuthSDK:92)
W/System.err:     at com.apple.android.sdk.authentication.a.b(AuthSDK:67)
W/System.err:     at com.apple.android.sdk.authentication.a.b(AuthSDK:56)
W/System.err:     at com.apple.android.sdk.authentication.SDKUriHandlerActivity.onCreate(AuthSDK:43)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8183)
W/System.err:     at android.app.Activity.performCreate(Activity.java:8167)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1316)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3751)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3950)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2377)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:262)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:8304)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
D/AuthUtils: deeplinkAppleMusic: activityNotFound!
D/AuthUtils: sendMarketIntent : uri = musicsdk://applemusic/authenticate-v1?appPackage=PACKAGE_ID&devToken=DEV_TOKEN_HERE
D/AuthUtils: sendMarketIntent: uri = market://details?id=com.apple.android.music&referrer=musicsdk%3A%2F%2Fapplemusic%2Fauthenticate-v1%3FappPackage%3DPACKAGE_ID%26devToken%DEV_TOKEN_HERE
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@dd295ee[]
D/ViewRootImpl[SDKUriHandlerActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false

There isn't much documentation for this anywhere, the apple site just refers to the code references and the AAR download site.

SDK Manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.apple.android.sdk.authentication"
    android:versionCode="1"
    android:versionName="1.2.0" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="28" />

    <application
        android:allowBackup="true"
        android:supportsRtl="true" >
        <activity
            android:name="com.apple.android.sdk.authentication.StartAuthenticationActivity"
            android:screenOrientation="portrait"
            android:theme="@style/MusicKitAuthTheme" >
        </activity>
        <activity
            android:name="com.apple.android.sdk.authentication.SDKUriHandlerActivity"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:exported="true"
            android:theme="@style/MusicKitAuthTheme" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="${applicationId}"
                    android:pathPattern="/authenticateresult.*"
                    android:scheme="musicsdk" />
            </intent-filter>
        </activity>
    </application>

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="com.apple.android.music" />
        </intent>
    </queries>

</manifest>
ibrhm117
  • 387
  • 3
  • 25
  • Is the app by any chance disabled? It is also possible that the sdk does not have `queries` element in its Manifest. – Darshan Jul 01 '22 at 05:23
  • Which Android API level did you build against. See: https://developer.android.com/training/package-visibility as the sample I found here: https://github.com/assembleinc/kids-tunes-android targets an older API. – Morrison Chang Jul 01 '22 at 05:26
  • @MorrisonChang I'm using android 12, and I did have to edit the manifest if the AAR to add the export section, then it would build properly. – ibrhm117 Jul 01 '22 at 05:39
  • @DarShan, no the app is not disabled at all, I just checked the AAR's manifest it does not have any queries element in its Manifest. – ibrhm117 Jul 01 '22 at 05:41
  • The major issue is that the AAR is compiled so there is no way for me to edit those specific sections and add the required code changes, also the AAR that apple provides was last updated on Dec 2, 2021, [LINK](https://developer.apple.com/download/all/?q=Android%20MusicKit) – ibrhm117 Jul 01 '22 at 05:44
  • You can add the `queries` element to your manifest with the specific package name. – Darshan Jul 01 '22 at 05:46
  • @DarShan , no luck it still redirects to the apple music on play store, I have updated the question with the manifest – ibrhm117 Jul 01 '22 at 05:57
  • @Darshan Did you figure out a solution for the redirection to the play store? – MedCh Jan 28 '23 at 14:08

1 Answers1

1

As Darshan says,

You can add the queries element to your manifest with the specific package name.

Per the following guide, the Apple Music app package name needs to be added in order for your app to interact with it: https://developer.android.com/guide/topics/manifest/queries-element

I fixed this in my own project by adding the following to AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
    ...
    <queries>
        <package android:name="com.apple.android.music" />
    </queries>

</manifest>

I'm assuming you filled in developer_token with your Apple Music developer token in your project and obfuscated it with DEV_TOKEN_HERE in the logs you posted.

B Wray
  • 11
  • 1
  • Yes, the DEV_TOKEN_HERE was obfuscated in the logs, yes I did add the queries element with the package name as Darshan had pointed out, but still no luck it wouldn't open the app and just redirected to the play store listing – ibrhm117 Jun 26 '23 at 05:47