Aspose.Slides for Android via Java: Initialization of a Presentation Failed

maven
implementation (
group: ‘com.aspose’,
name: ‘aspose-slides’,
version: ‘22.10’,
classifier: ‘android.via.java’)

And after new Presentation, it crash.
The code:

Presentation pre = new Presentation();

And output log:
12-27 15:30:40.605 23274 23274 D AndroidRuntime: Shutting down VM
12-27 15:30:40.609 23274 23274 E AndroidRuntime: FATAL EXCEPTION: main
12-27 15:30:40.609 23274 23274 E AndroidRuntime: Process: com.newskyer.draw, PID: 23274
12-27 15:30:40.609 23274 23274 E AndroidRuntime: java.lang.ExceptionInInitializerError
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at java.lang.Class.classForName(Native Method)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at java.lang.Class.forName(Class.java:454)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at java.lang.Class.forName(Class.java:379)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.internal.mh.for.if(Unknown Source:181)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.System.int.byte(Unknown Source:24)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.System.int.do(Unknown Source:99)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.System.int.do(Unknown Source:22)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.System.int.do(Unknown Source:6)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.are.(Unknown Source:7)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.GroupShape.(Unknown Source:50)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.BaseSlide.(Unknown Source:63)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.MasterSlide.(Unknown Source:0)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.adj.do(Unknown Source:8)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.am3.do(Unknown Source:179)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.Presentation.(Unknown Source:110)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.newskyer.draw.PadActivity.check(PadActivity.kt:983)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.newskyer.draw.PadActivity.onCreate(PadActivity.kt:963)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8488)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8461)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1343)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4602)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4842)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:113)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2928)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:117)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:205)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.os.Looper.loop(Looper.java:293)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:9596)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1204)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to read from field ‘com.aspose.slides.ms.backend.System.Drawing.int com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv.for’ on a null object reference
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv.int(Unknown Source:4)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.ms.backend.System.Drawing.int.do(Unknown Source:0)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.internal.ft.class.(Unknown Source:3)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: at com.aspose.slides.internal.ft.class.(Unknown Source:5)
12-27 15:30:40.609 23274 23274 E AndroidRuntime: … 33 more

@xjf,
Thank you for contacting support.

Please share the following additional data and information:

  • simple project that reproduces the error (you can zip the files and upload the archive here)
  • OS version on which the code was executed

Thank you for response.
OS version: Android 11.
And I think it is not related to system version.
I try these:

  1. Create a new Android project, it works.
  2. Integrated to my old project with same codes and same device. But it crash. I’m confused :disappointed_relieved:

Both of all, only have one line code.
Presentation pre = new Presentation();

@xjf,
I’ve added a ticket with ID SLIDESANDROID-470 to our issue-tracking system. Our development team will investigate the case. We will inform you of any progress.

Please also share information about the JDK version in your app.

@xjf,
Our developers have looked into the issue you are experiencing.

Unfortunately, we don’t know what you are doing specifically. But this problem says that we cannot get data about our “services”:
\META-INF\services\com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv
Could you please look into it in your old project?

Okay, the JKD version is 11.0.2.
And what’s \META-INF\services\com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv?

Unzip the release apk, I can find META-INF/services/com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv

@xjf,
I’ve forwarded your question to our developers. We will answer you ASAP.

Thanks, I found the reason. I set android:sharedUserId in AndroidManitest.xml, but I don’t found the solution yet.

@xjf,

This is the folder inside our jar. Could you check whether this folder is ignored in your project?

No, I can see this file in apk package file.
I try to remove android:sharedUserId from AndroidManitest.xml, it works.
But I need android:sharedUserId, because this app already published.
do you have any idea for this?

@xjf,
Could you please share the AndroidManitest.xml file?

OfficeTeset.zip (5.8 MB)

I upload the sample project. It will crash when run, but when remove the android:sharedUserId="com.office.test" from AndroidManifest.xml, it works.

and the AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="com.office.test"
package="com.example.officeteset">

        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:requestLegacyExternalStorage="true"
            android:supportsRtl="true"
            android:theme="@style/Theme.OfficeTeset">
            <activity android:name=".MainActivity"
                android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

I found a hack way to solve this issue :joy:
I try to use hack code for initialize GraphicsEnv, and it works.

@xjf,
If I understand correctly, the issue has already been resolved on your end. Could you please confirm?

Yes, but it is not a normal solution.

@xjf,
Thank you for the files and additional information. I’ve forwarded it to our developers.

@xjf,
Please try to add the following string to the application tag (before the activity tag):

<service android:enabled="true" android:name="com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv" />

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:sharedUserId="com.office.test"
    package="com.example.officeteset">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:requestLegacyExternalStorage="true"
        android:supportsRtl="true"
        android:theme="@style/Theme.OfficeTeset">

        <service android:enabled="true" android:name="com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv" /> <-- Slides service

        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Here is a link with more information about the service element:

I try to add the following :

<service android:enabled="true" android:name="com.aspose.slides.ms.backend.System.Drawing.GraphicsEnv" />

And it is not work.

But add the following before Presentation, it works.

Class<GraphicsEnv> clz = GraphicsEnv.class;
try {
    Field gdo = clz.getDeclaredField("do");
    gdo.setAccessible(true);
    gdo.set(new AndroidGraphicsEnvironment(), new AndroidGraphicsEnvironment());
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}

@xjf,
Unfortunately, we don’t have another idea to help you yet.