SAP / gigya-android-sdk

SAP CDC (Gigya) android sdk for mobile
Apache License 2.0
19 stars 13 forks source link

RuntimeException: Error creating Gigya SDK (did you forget to Gigya.setApplication or missing apiKey?) on version 7.0.3 #52

Closed burhanshakir closed 1 year ago

burhanshakir commented 1 year ago

The following issue seems to come up when trying to run the build with the Gigya Core SDK v7.0.3 on build variants with these flags:

isRemoveUnusedCode = true
isRemoveUnusedResources = true
isObfuscate = true
isOptimizeCode = true

The following exception is thrown as soon as the app is launched:

java.lang.RuntimeException: Unable to create application: java.lang.RuntimeException: Error creating Gigya SDK (did you forget to Gigya.setApplication or missing apiKey?)
                                                                                                        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6065)
                                                                                                        at android.app.ActivityThread.-wrap1(Unknown Source:0)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                        at android.os.Looper.loop(Looper.java:164)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6944)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

The SDK is initialized implicitly in the Application.kt class:

GigyaLogger.setDebugMode(BuildConfig.DEBUG)
Gigya.setApplication(this)
Gigya.getInstance().init(BuildConfig.SAP_API_KEY, "eu1.gigya.com", "CNAME")

the following rule has also been added to the proguard-rules.pro file

-keep class com.gigya.android.sdk.** { *; }

Are there any more rules that need to be added to the proguard file ?

Gigya core version: core-v7.0.3 Gigya NSS version: nss-v1.7.0

tal-mi commented 1 year ago

Hi,

Can you share your build.gradle release section so I can inspect the same configuration on my machine? In addition, I assume that "CNAME" is not the real value here...

Tal

burhanshakir commented 1 year ago

Hey @tal-mi thanks, sure here's the release section:

release {
            signingConfig = signingConfigs["upload"]
            postprocessing {
                proguardFiles += file("proguard-rules.pro")
                isRemoveUnusedCode = true
                isRemoveUnusedResources = true
                isObfuscate = true
                isOptimizeCode = true
            }

            buildConfigField(SapApiKey)
        }

Yeah CNAME is just a placeholder and not the real value

tal-mi commented 1 year ago

And you are encountering this when trying to build the variant or trying to run a release-signed APK file? Just to be sure so I will run the same configuration on my test application. Thanks for the info.

Tal

burhanshakir commented 1 year ago

@tal-mi No, the project builds fine, it's when running the APK on a device that causes the crash, and it's not just limited to a release signed variant, the same happens for any variant with the postprocessing flags enabled. The Dev variant here fails to work too:

create(BuildType.Dev) {
            signingConfig = signingConfigs["debug"]
            applicationIdSuffix = ".dev"
            isDebuggable = true
            postprocessing {
                proguardFiles += file("proguard-rules.pro")
                isRemoveUnusedCode = true
                isRemoveUnusedResources = true
                isObfuscate = true
                isOptimizeCode = true
            }

            buildConfigField(SapApiKey)

        }
burhanshakir commented 1 year ago

Hi @tal-mi any updates on this ?

Updating isRemoveUnusedCode = false seems to resolve this but this comes with its drawbacks. Can you please confirm if this is the only solution ?

Also this warning is thrown just before the crash occurs:

java.lang.InstantiationException: java.lang.Class<com.gigya.android.sdk.Gigya> has no zero argument constructor
at java.lang.Class.newInstance(Native Method)
at com.gigya.android.sdk.containers.IoCContainer.createInstance(IoCContainer.java:83)
at com.gigya.android.sdk.containers.IoCContainer.createInstance(IoCContainer.java:75)
at com.gigya.android.sdk.Gigya.getInstance(Gigya.java:130)

Not sure why this warning it thrown even though I am passing arguments when calling the getInstance method

Gigya.setApplication(this)
Gigya.getInstance(UserAccountGigya::class.java).init(BuildConfig.SAP_API_KEY, "eu1.gigya.com", BuildConfig.CNAME)
tal-mi commented 1 year ago

Hi,

Im looking into it. This may occur because the Android system does not know how to create the Gigya class on runtime due to the "removeUnusedCode" tag. This is new to me so I still need to investigate it further. At this point, I can confirm this is the only solution. It is best to open a support incident for this, as it may require further investigation that cannot be completed through the open source channel. https://developers.gigya.com/display/GD/Opening+A+Support+Incident