NativeScript / nativescript-fresco

This repository holds the NativeScript plugin that exposes the functionality of the Fresco image library to NativeScript developers.
Apache License 2.0
53 stars 23 forks source link

TypeError: Cannot read property 'AnimatedDrawable' of undefined #47

Closed oluwaseye closed 7 years ago

oluwaseye commented 7 years ago

VanillaJS nativescript project

app.js

var application = require("application");
application.start({ moduleName: "pages/home/home" });
var fresco = require("nativescript-fresco");
if (application.android) {
    application.onLaunch = function (intent) {
        fresco.initialize();
    };
}

home.xml

<page
  xmlns="http://schemas.nativescript.org/tns.xsd"
  xmlns:drawer="nativescript-telerik-ui/sidedrawer"
  xmlns:widgets="shared/widgets"
  xmlns:statusbar="nativescript-statusbar"
   xmlns="http://www.nativescript.org/tns.xsd"
   xmlns:nativescript-fresco="nativescript-fresco"
  loaded="pageLoaded">

<nativescript-fresco:FrescoDrawee row="0" height="160" imageUri="http://demo.megathe.me/pear/wp-content/uploads/2017/03/person24.jpg" />

Need some help. Here's the Exception from the plugin

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: 

Error calling module function 

Error calling module function 

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js, line: 92, column: 42

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5364)
    at android.app.ActivityThread.-wrap2(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: com.tns.NativeScriptException: 

Error calling module function 

Error calling module function 

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js, line: 92, column: 42

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

TypeError: Cannot read property 'AnimatedDrawable' of undefined
File: "<unknown>, line: 1, column: 265

StackTrace: 
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/tns_modules/nativescript-fresco/nativescript-fresco.js', line: 92, column: 43
    Frame: function:'require', file:'', line: 1, column: 266
    Frame: function:'', file:'file:///data/data/org.nativescript.MyApp/files/app/app.js', line: 2, column: 14
    Frame: function:'require', file:'', line: 1, column: 266

    at com.tns.Runtime.runModule(Native Method)
    at com.tns.Runtime.runModule(Runtime.java:521)
    at com.tns.Runtime.run(Runtime.java:513)
    at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:19)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5361)
    ... 8 more
oluwaseye commented 7 years ago

The plugin seems throw the exception above and java.lang.NullPointerException: SimpleDraweeView was not initialized

It seems the latest version does not play well with tns-core-modules v3.** even though it requires it.

In case anyone else runs into the same issue

My solution NaitveScript 3.2.* In your project

npm uninstall tns-core-modules --save
tns platform remove android

if you have the latest plugin tns plugin remove nativescript-fresco

Then install/add the following versions.

npm install tns-core-modules@2.5.0 --save
tns plugin add nativescript-fresco@1.0.16
tns platform add android@2.5.0

This is what worked. Hope the new version of the plugin gets fixed soon.

VladimirAmiorkov commented 7 years ago

Hi @oluwaseye ,

I just update the repositories demo app to the latest deps version (you can see them here) and did manage to run the project without any errors or issues what so ever. Maybe in your project there is a mismatch between nativescript-angular, angular itself and the tns-core-modules which is leading to this error.

Can you try to run the demo app from this repository and see if it runs on your side, you ca n follow this wiki page on how to build the source code and run the demo app.

VladimirAmiorkov commented 7 years ago

@oluwaseye What do you mean by

NaitveScript 3.2.*

The latest and current version of NativeScript is 3.1.3 and tns-core-modules is 3.1.1

oluwaseye commented 7 years ago

@VladimirAmiorkov I meant the latest Nativescript. I'll try the demo app and let you know if it works running the latest tns-core-modules.

oluwaseye commented 7 years ago

Should have posted this a while back. @VladimirAmiorkov On a Pure JS Nativescript core project, here's what finally worked when initializing in the app.js file.

application.on("launch", function () {
        fresco.initialize();
  });

and not this, as shown in the README

  application.onLaunch = function (intent) {
        fresco.initialize();
    };

Thanks

VladimirAmiorkov commented 7 years ago

Hi, it looks like the readme was not updated with the breaking change ofthe launch event. Feel free to make a PR if you want to help the community, thank you for bringing this to our my attention.

On Fri, Sep 8, 2017, 14:25 Oluwaseye notifications@github.com wrote:

Should have posted this a while back. @VladimirAmiorkov https://github.com/vladimiramiorkov On a Pure JS Nativescript core project, here's what finally worked when initializing in the app.js file.

application.on("launch", function () { fresco.initialize(); });

and not this, as shown in the README

application.onLaunch = function (intent) { fresco.initialize(); };

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NativeScript/nativescript-fresco/issues/47#issuecomment-328078485, or mute the thread https://github.com/notifications/unsubscribe-auth/AEwh4w6NWhXoj8ylUNFpxPNoJ92KVlddks5sgSQkgaJpZM4O4yko .

--

Vladimir Amiorkov Email: v.amiorkov@gmail.com

oluwaseye commented 7 years ago

Awesome!. Glad to contribute to the community. Created a pull request with the updated Launch event.

VladimirAmiorkov commented 7 years ago

Closing this issue, resolution here