MS4Plugin icon indicating copy to clipboard operation
MS4Plugin copied to clipboard

Unable to install into Ionic project

Open remib opened this issue 8 years ago • 10 comments

I've installed the plugin fine on iOS using the latest version of ionic however the installation instructions for Android do not seem to apply any more. For a start, Eclipse is no longer supported. Is it possible to use this plugin with Ionic? I believe Cordova now uses Gradle to build for Android.

remib avatar Apr 08 '16 17:04 remib

Hi remib, first of all it's great to hear that the plugin is working fine with ionic on iOS -- we don't have time to test the plugin with third-party frameworks so that's great to hear.

Secondly, thanks for your bug report for Android. Last time we did a big update for the plugin, Phonegap support for Android Studio was very poor. Looking again now I see that Phonegap and Android Studio work well together and we will investigate again.

We will start looking at this on Tuesday and of course I cannot be sure how long it will take us. Expect to hear more in one week.

If you have a deadline that you need to meet please contact me offline and we can discuss how we meet it.

thomasforth avatar Apr 08 '16 18:04 thomasforth

Thanks for the swift response. To clarify, we are using Cordova, not Phonegap. I know the two are technically the same but there may be differences that are contributing to the issues I'm facing.

I've managed to import my cordova/Ionic project into Android Studio and added the Moodstocks SDK however I'm getting errors in CordovaFragment.java. For you reference this is what I did:

  1. Download Moodstocks SDK for Android Studio and extract
  2. Create Ionic/Cordova project
  3. Edit config.xml and replace name and id (bundle id/package name) i.e. my.package.name
  4. Add Android platform from CLI
  5. In Android Studio, import/open project and select the platforms/android folder
  6. Delete MainActivity.java from my.package.name folder and replace with the one from the plugin
  7. In MainActivity.java, replace _yourKey_ and _yourSecret_ with the ones from the Moodstocks Apps page
  8. In Finder/Windows explorer, copy and paste moodstocks-native.jar and moodstocks.jar from the SDK downloaded in step 1 to platforms/android/libs
  9. In Android studio project explorer expand jniLibs, right-click moodstocks.jar and click 'Add as Library'
  10. Change all references to com.imactivate.MS4TOM and com.imactivate.example

Now the only issue I'm facing is these errors in CordovaFragment.java: ~~Error:(53, 8) error: CordovaFragment is not abstract and does not override abstract method hasPermission(String) in CordovaInterface~~ ~~Error:(67, 18) error: cannot find symbol method setBackgroundColor(int)~~ ~~Error:(72, 13) error: cannot find symbol method setLayerType(int,<null>)~~ Error:(98, 22) error: cannot find symbol variable pluginManager Error:(99, 22) error: cannot find symbol variable pluginManager ~~Error:(135, 10) error: CordovaFragment.CordovaContext is not abstract and does not override abstract method hasPermission(String) in CordovaInterface~~

And here's the stacktrace:

~~java.lang.NoSuchMethodException: org.apache.cordova.CordovaWebView.<init>(android.content.Context, android.util.AttributeSet) at java.lang.Class.getConstructor0(Class.java:2763) at java.lang.Class.getConstructor(Class.java:1693) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:389) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:170) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:103) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:168) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:394) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498) at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610) at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607) at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607) at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629) at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320) at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310) at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269) at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227) at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217) at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238) at com.intellij.util.Alarm$Request$1.run(Alarm.java:351) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:695)~~

In AndroidManifest.xml I have set minSdkVersion="16" (Ionic default) and android:name="MainActivity"

EDIT: This could shed some light on the situation https://github.com/Adobe-Marketing-Cloud-Apps/app-sample-android-phonegap/issues/1

EDIT 2: I realised I was using cordova v5.1.1. I removed the android platform and re-added with Cordova version 4.1.1 and the Fragment error is no longer there. However, the setBackgroundColor(int), setLayerType(int,<null>) and pluginManager errors persisted. I fixed the first 2 by adding getView() like this:

myWebView.getView().setBackgroundColor(Color.argb(1, 0, 0, 0)); myWebView.getView().setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); (Thanks to https://github.com/mbppower/CordovaCameraPreview/issues/40#issuecomment-112781231)

However this did not work for pluginManager. I've had a look around online but I can't solve this one. Any ideas?

remib avatar Apr 11 '16 11:04 remib

Hello @remib , I am facing the same problem.

I use Ionic, and the latest Cordova platform for Android (5.1.1).

For the error with CordovaFragment and missings methods, I simply add the missings methods in CordovaFragment.java, both for the internal class CordovaContext and the upper class CordovaFragment.

@Override
public void requestPermission(CordovaPlugin plugin, int requestCode, String permission) {

}

@Override
public void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {

}

@Override
public boolean hasPermission(String permission) {
    return false;
}

I was blocked with the setBackgroundColor, and setLayerType, and your Edit 2 help me : add getView() after myWebView to have

myWebView.getView().setBackgroundColor()
myWebView.getView().setLayerType()

For the problem of pluginManager, simply replace

if (myWebView.pluginManager != null) {
    myWebView.pluginManager.onDestroy();
}

with

if (myWebView.getPluginManager() != null) {
    myWebView.getPluginManager().onDestroy();
}

After these modifications, the Project build well. But on device, the app has a runtime error :

Caused by: android.view.InflateException: Binary XML file line #7: Class is not a View org.apache.cordova.CordovaWebView
[...]
at com.moodstocks.phonegap.plugin.CordovaFragment.onCreateView(CordovaFragment.java:65)

The problem come from the line 65 in class CordovaFragment.java

View rootView = localInflater.inflate(R.layout.fragment_cordova, container, false);

The R.layout.fragment_cordova is a XML layout which contains

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="0dp">

    <org.apache.cordova.CordovaWebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id = "@+id/myWebView"/>

</LinearLayout>

From here, I do not understand why the inflater throw this error.

An other issue seems to be related with this one : https://github.com/thomasforth/MS4Plugin/issues/6#issuecomment-165524089

hmichelkernix avatar Apr 12 '16 09:04 hmichelkernix

Thanks a lot for your input! I've added your suggested amends to the pluginManager call and the project now builds however it still will not run on the device. I get the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package.name/my.package.name.MainActivity}: android.view.InflateException: Binary XML file line #7: Class is not a View org.apache.cordova.CordovaWebView

I think this all stems from this issue I posted above https://github.com/Adobe-Marketing-Cloud-Apps/app-sample-android-phonegap/issues/1.

I should point out that the Author of the plugin is aware of issues when using Cordova 5.x so I would suggest you try downgrading to 4.1.1 by removing the android platform and add it again using ionic platform add [email protected]. Don't forget to make a backup of your project first though!

Cordova 5.x compatibility

We know of people successfully using our plugin with every 3.x and 4.x version of Cordova. Cordova 5.x introduces a large number of small bugs. We have fixed most of them, with a few left to squash. Unfortunately these fixes break compatibility with previous version of Cordova and we expect many of them to fixed within Cordova itself in future 5.x versions. For now, we recommend avoiding Cordova 5.x, and we cannot provide support for it.

remib avatar Apr 12 '16 12:04 remib

@remib I solved this issue by rewriting the CordovaFragment class as demonstrated here https://github.com/thomasforth/MS4Plugin/issues/6#issuecomment-165524089

I do not want to downgrade Cordova to 4.1.1, I have many others plugins to maintain... :)

hmichelkernix avatar Apr 12 '16 12:04 hmichelkernix

Thanks, my App is now running on Android with Cordova 4.1.1. If you find a way to make it work on the latest version of Cordova, please share.

remib avatar Apr 12 '16 13:04 remib

My app is under Cordova Android 5.1.1 and is now running well. All the modifications I have done are in this issue. If I have some time, I will maybe fork this project for having cordova 5 support.

hmichelkernix avatar Apr 12 '16 13:04 hmichelkernix

Oh ok sorry, I misunderstood! I may try a rebuild for the latest version then.

remib avatar Apr 12 '16 13:04 remib

For your reference, I have just tried to build a signed APK and got this error: cordova Expected resource of type id [ResourceType] in CordovaFragment.java

To resolve this lint error, replace myWebView.getView().setId(100); with myWebView.getView().setId(Integer.valueOf(100));

remib avatar Apr 21 '16 11:04 remib

@hmichelkernix see #11

remib avatar May 25 '16 14:05 remib