airsdk / ANE-PlayAssetDelivery

Play Asset Delivery ANE
2 stars 2 forks source link

Any proper example on how to use PlayAssetDelivery (How to pack asset packs)? #21

Open hantouan opened 2 months ago

hantouan commented 2 months ago

Is there any proper (complete) example available on how to use this ANE, or the API, cannot find any of those. trying to include it in my project, and i m keep getting the error message:

-1046: Type was not found or was not a compile-time constant: AssetFile.

(using adobe animate 2024, AIR SDK 50.2.4.5

hantouan commented 2 months ago

I managed to publish the APK file successfully, but the .aab file isn't generated. I m using Adobe Animate, should I use the command line for publishing? I can't find the steps needed, I have always used Adobe Animate for publishing applications.

Thanks in advance.

ajwfrost commented 2 months ago

Animate doesn't (yet?) directly support Android App Bundles, so you could use the command line, or you could look at the workaround option: https://airsdk.dev/docs/tutorials/platform/android/packaging-android-app-bundles#ides-without-aab-option

hantouan commented 2 months ago

Thank you very much, I appreciate the quick response.

hantouan commented 2 months ago

I don't understand what am I doing wrong, here are the steps I follow: I publish the project to an .aab file following the workaround mentioned above, then I use bundletool to create the .apks and using the bundletool again to install the app on device for device testing. The application seems to install correctly on device, but when I try to access the asset pack files (it is an istall-time asset pack) using openInstallTimeAsset, I get a null asset. I tried to get the status of the asset pack, after I initialize the PlayAssetDelivery (which initializes seccessfully), and the status code is 0 (UNKNOWN).

The path I provide in openInstallTimeAsset is the relative to asset pack folder(lets say assets/), not including that i.e (sounds/file.mp3).

Thank you in advance.

ajwfrost commented 2 months ago

Just checking, have you added the extra services that are required for this in the manifest additions in your app descriptor file? See the "Configure the application" section of the wiki: https://github.com/airsdk/ANE-PlayAssetDelivery/wiki

hantouan commented 2 months ago

Yes, I copied that section from there and added the extensionIds as well.

hantouan commented 2 months ago

Here is the section for android:

    <android>
          <assetPacks>
              <assetPack delivery="install-time" folder="assets/" id="soundAssets"/>
        </assetPacks>
          <manifestAdditions><![CDATA[
            <manifest android:installLocation="auto">
                <uses-sdk android:minSdkVersion="22" android:targetSdkVersion="33"  />
                <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
                <uses-permission android:name="android.permission.INTERNET"/>
                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
                <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
                <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
                <uses-permission android:name="android.permission.WAKE_LOCK"/>
                <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
                <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
                <application android:enabled="true">
                    <activity
                        android:name="com.google.android.play.core.common.PlayCoreDialogWrapperActivity"
                        android:enabled="false"
                        android:exported="false"
                        android:stateNotNeeded="true" />
                    <service
                        android:name="com.google.android.play.core.assetpacks.AssetPackExtractionService"
                        android:enabled="false"
                        android:exported="true" />
                    <service
                        android:name="com.google.android.play.core.assetpacks.ExtractionForegroundService"
                        android:enabled="false"
                        android:exported="false" />
                </application>
            </manifest>]]>
        </manifestAdditions>
    </android>
    <versionLabel>1.3.1</versionLabel>

  <supportedLanguages>en</supportedLanguages>

  <extensions>
    <extensionID>com.harman.PlayAssetDelivery</extensionID>
    <extensionID>com.google.android.play</extensionID>
  </extensions>
marchbold commented 2 months ago

Documentation might need a slight update (I'll look into it) but the minimum manifest additions should look like this:

<manifest android:installLocation="auto">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
  <!-- Permission will be merged into the manifest of the hosting app. -->
  <!-- Is required to launch foreground extraction service for targetSdkVersion 28+. -->
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <!-- Is required to launch foreground extraction service for targetSdkVersion 34+. -->
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
  <!-- Required permission for App measurement to run. -->
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission
    android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />
  <!-- Required by older versions of Google Play services to create IID tokens -->
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <application>
    <!-- The activities will be merged into the manifest of the hosting app. -->
    <activity android:name="com.google.android.play.core.common.PlayCoreDialogWrapperActivity"
      android:exported="false" android:stateNotNeeded="true"
      android:theme="@style/Theme.PlayCore.Transparent" />
    <!-- The services will be merged into the manifest of the hosting app. -->
    <service android:name="com.google.android.play.core.assetpacks.AssetPackExtractionService"
      android:enabled="false" android:exported="true">
      <meta-data android:name="com.google.android.play.core.assetpacks.versionCode"
        android:value="20201" />
    </service>
    <service android:name="com.google.android.play.core.assetpacks.ExtractionForegroundService"
      android:enabled="false" android:exported="false" android:foregroundServiceType="dataSync" />
    <receiver android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
      android:enabled="true" android:exported="false" />
    <service android:name="com.google.android.gms.measurement.AppMeasurementService"
      android:enabled="true" android:exported="false" />
    <service android:name="com.google.android.gms.measurement.AppMeasurementJobService"
      android:enabled="true" android:exported="false"
      android:permission="android.permission.BIND_JOB_SERVICE" />
    <meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
    <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
      android:exported="false" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    <service android:name="com.google.firebase.components.ComponentDiscoveryService"
      android:exported="false">
      <meta-data
        android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
        android:value="com.google.firebase.components.ComponentRegistrar" />
    </service>
  </application>
</manifest>

And you'll need the following extensions:

  <extensions>
    <extensionID>com.distriqt.playservices.Base</extensionID>
    <extensionID>com.google.android.play</extensionID>
    <extensionID>com.harman.PlayAssetDelivery</extensionID>
    <extensionID>com.jetbrains.kotlin</extensionID>
  </extensions>

Highly recommend using apm

apm install com.harman.PlayAssetDelivery
apm generate app-descriptor
hantouan commented 2 months ago

Hello and thank you for your response. Is the kotlin ane needed?

hantouan commented 2 months ago

I did everything above and still getting the same error: TypeError: Error #1009: Cannot access a property or method of a null object reference.

sample code:

var assets:PlayAssetDelivery = App.Instance.GetAssets();
if (assets == null)
{
    trace("PlayAssetDelivery is null!");
}

var strPath:String = assets.getAssetAbsolutePath("soundAssets", soundId);
trace("strPath: " + strPath); // path is null here....

var soundBytes:ByteArray = new ByteArray();
var asset:AssetFile = assets.openInstallTimeAsset(soundId);

asset is null here!!!

hantouan commented 2 months ago

Any suggestions?

marchbold commented 2 months ago

What does GetAssets() do? Could you post the logs from the device as well?

hantouan commented 2 months ago

GetAssets() returns the initialized PlayAssetDelivery. I will post the logs in a while.

hantouan commented 2 months ago

Here is the log, i hope it helps. log.txt

ajwfrost commented 2 months ago

Hmm - I'm wondering if this is due to some versioning mismatches...

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/tasks/TaskCompletionSource;

Can I check which version of the Play Asset Delivery ANE you have, and of the com.google.android.play.ane one too? If you open the .ane files within a zip manager and look for "META-INF/ANE/extension.xml", you should see a "versionNumber" field.

In our version 9, we updated to use the com.google.android.play:asset-delivery package, with an associated switch in Java including from com.google.android.play.core.tasks.Task to com.google.android.gms.tasks.Task.

@marchbold are you able to confirm whether there's a particular version of the play ANE that would be needed to correspond with this? Or is it more that we would need to also specify a Gradle dependency upon a GMS package within the ANE platform file? (there wasn't anything in the migration steps for this .. but reading between the lines, I would think that we perhaps need this too..?)

ajwfrost commented 2 months ago

Update -> we maybe need to include a dependency on

com.google.android.gms:play-services-tasks:18.1.0

Let me get that updated and see whether it helps.

FYI we were also trying to get our test app into a suitable state for publishing as sample code, but running into some "interesting" issues with Android platform (compile sdk level) 34...

ajwfrost commented 2 months ago

@hantouan are you able to try with the attached ANE please? (this is zipped up, so unzip it to get at the .ane file)

thanks

PlayAssetDelivery.ane.zip

hantouan commented 2 months ago

I will try that in the morning, can't do that right now

hantouan commented 2 months ago

d

The ANE versionNumber is 9

marchbold commented 2 months ago

This would indicate you are missing the com.distriqt.playservices.Base extension. Check the updated docs here for the required extension list:

https://github.com/airsdk/ANE-PlayAssetDelivery/wiki/Get-Started

hantouan commented 2 months ago

Still getting the same errors.

log.txt

marchbold commented 2 months ago

Did you grab the latest release?

hantouan commented 2 months ago

Yes, everything are the latest from https://github.com/airsdk/ANE-PlayAssetDelivery/wiki/Get-Started, except the PlayAssetDelivery.ane that I downloaded from the link above (version 10).

Is there a chance that I have made errors while packaging the app?

The steps I followed are:

1) Publishing in Adobe Animate, having set the CreateAndroidAppBundle to true to create the aab file.

2) Then I build the apks using the bundletool as follows: bundletool-all-1.16.0.jar build-apks --bundle="App(64bit).aab" --output="App(64bit).apks" --ks="App.jks" --ks-pass=pass:mypass --ks-key-alias=mykeyalias

and finally 3) I install the app on device: bundletool-all-1.16.0.jar install-apks --apks="App(64bit).apks" --adb="F:\AndroidSDK\android-sdk\platform-tools\adb.exe"

ajwfrost commented 2 months ago

Ah .. so, trying it here, and it looks like it doesn't work if we have that dependency just included in the grade build file for the ANE code itself... we need that to be included within the main application that links in the ANE.

So we would need to switch to add this gradle dependency into the ANE as a separate (XML-based) dependency rather than having this in the ANE java build configuration.

.... will get an updated version prepared and hopefully check it here before posting, we've managed to get a reproduction of the issue I think..

ajwfrost commented 2 months ago

@hantouan please try with this ANE file: PlayAssetDelivery.ane.zip

To install it, you can use ADT:

adt -installApp -package "App(64bit).aab"

because internally that would just do the same as the two bundletool commands (assuming bundletool already knows about your keystore, i.e. if you've ever built any debug stuff in Android Studio..)

FYI we've also put our test case now up online: https://github.com/airsdk/Adobe-Runtime-Support/tree/master/samples/android_play_asset_delivery

thanks

hantouan commented 2 months ago

I built and run the test case and it seems it works, but not for install-time assets, here is the output:


ANE is supported

Checking status for install-time asset pack

Could not read install-time asset file

Checking status for asset pack: fast_follow_asset_pack

Asset pack not found: requesting

Status event -> fast_follow_asset_pack, 1

Status event -> fast_follow_asset_pack, 2

Download Progress = 50%

Status event -> fast_follow_asset_pack, 3

Transfer Progress = 0%

Status event -> fast_follow_asset_pack, 4

Status event -> fast_follow_asset_pack, 4

Checking status for asset pack: on_demand_asset_pack

Asset pack not found: requesting

Status event -> on_demand_asset_pack, 1

Status event -> on_demand_asset_pack, 2

Download Progress = 0%

Status event -> on_demand_asset_pack, 3

Transfer Progress = 0%

Status event -> on_demand_asset_pack, 4

Status event -> on_demand_asset_pack, 4

ajwfrost commented 2 months ago

Did you install the bundle via ADT? I think your manual bundletool usage is missing the "local testing" flag. See e.g. https://stackoverflow.com/a/67542386

If it's not working after adding that, can you capture logcat output for it (either from Android Studio / ADB, or adt -deviceLog -platform android)

thanks

hantouan commented 2 months ago

log.txt

Did you install the bundle via ADT? I think your manual bundletool usage is missing the "local testing" flag.

I used adt this time.

ajwfrost commented 2 months ago

That's odd .. nothing massively obvious in the log but the test case works for me.

Can I suggest uninstalling the app from your phone and rebooting it? then re-install.. (and maybe even change the application ID?) - potentially it got into a weird scenario with the older version and maybe didn't install the install-time APK properly....

thanks

hantouan commented 2 months ago

Same thing :).

I have also changed the ID. Is there any chance that my phone is the problem? it is a samsung A20e.