Start a new topic
Solved

cordova makes cordova.requre variable undefined (Sorry, I wrote in Japanese last time, so I'll post a new one.)

Hello.

 I have a problem that I just can't solve.

When I apply loadARchitectWorld, app.wikitudePlugin is undefined.

In the console.log () to download loadARchitectWorld, the content of app.wikitudePlugin was undefined and undefined.

The app, "app.wikitudePlugin = cordova.require (" com.wikitude.phonegap.wikitudeplugin.WikitudePlugin ");" showed up, already.

Is it undefined?


cordova wikitude plugin: 9.8.0

cordova : 10 

xcode : 12.5.1


Translated with www.DeepL.com/Translator (free version)


Hi,


Did you try if the same issue is happening in our sample application https://github.com/Wikitude/wikitude-cordova-plugin-samples?


So far I couldn't reproduce your issue, but the log itself is pointing to an importing error with our WikitudePlugin which is not happening in my end. Please have a look at our sample app and let me know if you can also reproduce the same issue there with the exact steps.


Regards,


Aitor.

   

Thanks for the reply.


I created another app with the same conditions, and it works fine there.

The difference is the way wikitudo is installed.

The previous app was installed from the terminal via github when 9.8.0 was the latest.

In contrast, this time I downloaded it locally from the wikitude website and then installed it in the app.

Is there a difference here?

By the way, when I build the same app in monaca, wikitude works.

But I can't upload to Apple from monaca, so I'm having trouble.

Is there a way to install it other than via local?

I've already purchased the 9.8.0 license by itself, so I can't use the latest version.


Thank you very much for your help.

Hi,


There shouldn't be differences, but our suggestion is to always follow the documentation. In this case, I would suggest to have a look at https://www.wikitude.com/external/doc/documentation/latest/phonegap/setupguidecordovacli.html#setup-guide-cordova-cli where we include the plugin via terminal.


Regarding the issue with Apple, is there an error log that we could check? I'm afraid that without the error it is a bit difficult for us to suggest you next steps or a way to solve it.


Regards,


Aitor.

 Thanks for the reply.


Below is the error log that comes up in the safari console.


*******************************************************************************************************************************

[Error] TypeError: undefined is not an object (evaluating 'app.wikitudePlugin.loadARchitectWorld')
 toAR (index.js:178)
 tappedFudatoriBnr (map.js:1084)
 onclick (Script Element 18:1)

*******************************************************************************************************************************


I've included the source code for index.js just in case.


Thank you for your cooperation.

//Wikitudeのindex.html用スクリプト

var app = {
    // アプリケーションコンストラクタ
    initialize: function() {
      this.bindEvents();
    },
    // イベントリスナーをバインドする
    // 起動時に必要なイベントをバインドします。一般的なイベントは次のとおりです。
    // 'load'、 'deviceready'、 'offline'、 'online'などがあります。
    bindEvents: function() {
        document.addEventListener('deviceready', app.onDeviceReady, false);
      
    },
      // devicereadyイベントハンドラ
      // 「this」の範囲がイベントです。 'receivedEvent'関数を呼び出すには、明示的に 'app.receivedEvent(...);'を呼び出す必要があります。
    onDeviceReady: function() {
      console.log("wikitudePluginのonDeviceReady");
      app.wikitudePlugin = cordova.require("com.wikitude.phonegap.wikitudeplugin.WikitudePlugin");
      
      app.wikitudePlugin.isDeviceSupported(app.onDeviceSupported, app.onDeviceNotSupported, [ "geo"]);
      //app.receivedEvent('deviceready');
    },
  
  onDeviceSupported: function() {
      
      console.log("このデバイスはARをサポートしています");
      
        // ARchitectからPhoneGapに通信するためのコールバックの設定
        app.wikitudePlugin.setOnUrlInvokeCallback(app.onURLInvoked);
      
  },
  onDeviceNotSupported: function(errorMessage) {
      //alert(errorMessage);
      console.log("このデバイスはARをサポートしていません");
  },
  onARExperienceLoadedSuccessful: function(loadedURL) {
      
    /* 必要な場合は、拡張現実体験のロードに成功する */
    console.log("ARのロードに成功しました");
      
    //app.wikitudePlugin.callJavaScript('alert(\'テスト\')');
       
    //ローケーションARへ「札ID」「一文字目」「札位置情報」のパラメータを渡す必要があるため、ここからメッソドをコール
    app.wikitudePlugin.callJavaScript('World.init(' + HUDAID + ',\'' + ICHIJI + '\',' + FUDALOCATION.lat + ',' + FUDALOCATION.lng + ',' + RELATIVE + ',' + ANIMEPATTERN + ')'); 
                
        
  },
  onARExperienceLoadError: function(errorMessage) {
      
    //alert('Loading AR web view failed: ' + errorMessage);
    console.log("ARのロードに失敗しました");
    
    dbErrAlert("0601");
    
    //app.wikitudePlugin.callJavaScript('alert(\'ARのロードに失敗しました\')');
      
  },
  
    //----------------------------------------------------------------------------吉田
    onURLInvoked: function(url) {
        
        //ar.js より受け取ったパラメーターを判別
        if ( 'closeWikitudePlugin' == url.substring(22) ) {
            
            //ボタン効果音
            playButton();
            
            //札ッシュモードBGM
            playFudashBGM();
            
            //札取りモードフラグ
            FUDATORI_FLG = false;
            
            //ARを閉じる
            app.wikitudePlugin.close();
            
        }else if ( 'toResult' == url.substring(22) ) {
            
            //効果音
            playSha();
            
            //バイブレーション
            vibration();
            
            if(WATCHID){
                //watchPositionの追跡を止める
                navigator.geolocation.clearWatch(WATCHID);
                WATCHID = null;
            }
            
            if(COMPASS_WATCH_ID){
                //方位の監視を停止
                navigator.compass.clearWatch(COMPASS_WATCH_ID);
                COMPASS_WATCH_ID = null;
            }
            
            //マップ表示中フラグ
            MAPHYOUJICHUFLG = false;
            
            //札をとったらDBにユーザーIDと札IDを登録する
            onFudaBtn_();
            
            //0.5秒後に
            setTimeout(function() {
                
                //効果音
                playHai();
                
                //2秒後に
                setTimeout(function() {
                    
                    //BGM停止
                    stopBGM();
                    
                    //札取りモードフラグ
                    FUDATORI_FLG = false;
                    
                    //リザルトページへ遷移
                    document.querySelector('#navigator').pushPage('result.html',{animation: 'fade'});
                    
                    //ARを閉じる
                    app.wikitudePlugin.close();
                
                }, 2000);
                
            }, 500);
            
        
        }else if ( 'shippai' == url.substring(22) ) {
            
            //効果音
            playSha();
            
            //バイブレーション
            vibration();
            
            //0.5秒後に
            setTimeout(function() {
                
                //乱数を作成
                var rand = Math.floor( Math.random() * 2 ) ;
                
                if(rand == 0){
                    //ビヨヨーン効果音
                    playBiyoyon();
                }else{
                    //おてつき効果音
                    playOtetsuki();
                }
                
            }, 500);
        
        }else{
            
            //alert('ARchitect => PhoneGap ' + url);
            
        }  
    },
  
  // 受け取ったイベントのDOMを更新する
  receivedEvent: function(id) {
      var parentElement = document.getElementById(id);
      var listeningElement = parentElement.querySelector('.listening');
      var receivedElement = parentElement.querySelector('.received');
      
      listeningElement.setAttribute('style', 'display:none;');
      receivedElement.setAttribute('style', 'display:block;');
      
      console.log('Received Event: ' + id);
  }
};


//ARコンテンツへ遷移
function toAR(){
    
    app.wikitudePlugin.loadARchitectWorld(
      app.onARExperienceLoadedSuccessful, 
      app.onARExperienceLoadError,
      "www/ar.html",
      [ "geo"],
      {"camera_position": "back"}
    );
    
};

app.initialize();


 

Hi,


We found out that our Cordova Wikitude Plugin 9.8.0 version was not properly uploaded in the package manager -> https://www.npmjs.com/package/com.wikitude.phonegap.wikitudeplugin


Now the 9.8.0 version should be ready to be used via terminal. We do apoligize for the inconvinience that it could cause.


Please let me know if everything works fine now or if there is still issues with the builds.


Regards,


Aitor.

Hi.


I couldn't download the file from npm because I got an error.

I downloaded 9.8.0 from the website again and added it to the project, but no change.

As for the phenomenon of "undefinde" before calling "loadARchitectWorld", I copied only the www folder of the application that was working properly under the same conditions and replaced it with the www folder where the problem was occurring, and it worked.

Is it still a problem with index.js?

Please check the index.js file that is working.


 

//Wikitudeのindex.html用スクリプト

var ARFLAG = false;

var app = {
    // アプリケーションコンストラクタ
    initialize: function() {
      this.bindEvents();
    },
    // イベントリスナーをバインドする
    // 起動時に必要なイベントをバインドします。一般的なイベントは次のとおりです。
    // 'load'、 'deviceready'、 'offline'、 'online'などがあります。
    bindEvents: function() {
        document.addEventListener('deviceready', app.onDeviceReady, false);
      
    },
      // devicereadyイベントハンドラ
      // 「this」の範囲がイベントです。 'receivedEvent'関数を呼び出すには、明示的に 'app.receivedEvent(...);'を呼び出す必要があります。
    onDeviceReady: function() {
      console.log("wikitudePluginのonDeviceReady");
      app.wikitudePlugin = cordova.require("com.wikitude.phonegap.wikitudeplugin.WikitudePlugin");
      
      app.wikitudePlugin.isDeviceSupported(app.onDeviceSupported, app.onDeviceNotSupported, [ "geo"]);
      //app.receivedEvent('deviceready');
    },
    onDeviceSupported: function() { 
      console.log("このデバイスはARをサポートしています");
      // ARchitectからPhoneGapに通信するためのコールバックの設定
      //app.wikitudePlugin.setOnUrlInvokeCallback(app.onURLInvoked);
      app.wikitudePlugin.setJSONObjectReceivedCallback(app.onJSONObjectReceived);
      
    },
    onDeviceNotSupported: function(errorMessage) {
      //alert(errorMessage);
      console.log("このデバイスはARをサポートしていません");
      //アラート
      ons.notification.alert({
        title: 'ARエラー',
        messageHTML: '<p>このデバイスはARをサポートしていません。</p>',
        buttonLabel: ['OK'],
        callback: function(){
        
        }
      });
    },
    onARExperienceLoadedSuccessful: function(loadedURL) {
      /* 必要な場合は、拡張現実体験のロードに成功する */
      console.log("ARのロードに成功しました"); 
      //app.wikitudePlugin.callJavaScript('alert(\'テスト\')');
      //ローケーションARへ「札ID」「一文字目」「札位置情報」のパラメータを渡す必要があるため、ここからメッソドをコール
      console.log('loadedURL:' + loadedURL);
      console.log('COURSE:'+ COURSE);
      console.log('course type:' + typeof(COURSE));
      console.log('SPOTID:' + SPOTID);
      console.log('SPOTLOCATION.lat:' + SPOTLOCATION.lat);
      console.log('SPOTLOCATION.lng:' + SPOTLOCATION.lng);
      console.log('RELATIVE:' + RELATIVE);
      console.log('ANIMEPATTERN:' + ANIMEPATTERN);
      app.wikitudePlugin.callJavaScript('World.init(\'' + COURSE + '\',\'' + SPOTID +'\',' + SPOTLOCATION.lat + ',' + SPOTLOCATION.lng + ',' + RELATIVE + ',' + ANIMEPATTERN + ')');
      console.log('AR開始');
    },
    onARExperienceLoadError: function(errorMessage) {
      alert('Loading AR web view failed: ' + errorMessage);
      console.log("ARのロードに失敗しました:" + errorMessage);
      app.wikitudePlugin.callJavaScript('alert(\'ARのロードに失敗しました\')');
    },
    
    onJSONObjectReceived: function(json) {
      //console.log('json:' + json);
      //console.log('url.substring(22):' + url.substring(22) );
      //ar.js より受け取ったパラメーターを判別
      if ( 'closeWikitudePlugin' == json.action ) {
        //BGM停止
        stopBGM();
        //札ッシュモードBGM
        playBGM('meguri_bgm');
        //札取りモードフラグ
        SPOTTORIFLAG = false;
        //ARを閉じる
        app.wikitudePlugin.close();
      }else if ( 'ToTop' == json.action ) {
        //BGM停止
        stopBGM();
        //札ッシュモードBGM
        //playBGM('meguri_bgm');
        //札取りモードフラグ
        SPOTTORIFLAG = false;
        //ARを閉じる
        app.wikitudePlugin.close();
        toTop();
      }else if ( 'toResult' == json.action ) {
        //効果音
        playSE('onclick');
        //バイブレーション
        vibration();
        /*if(WATCHID){
          //watchPositionの追跡を止める
          navigator.geolocation.clearWatch(WATCHID);
          WATCHID = null;
        }*/
        //マップ表示中フラグ
        //MAPHYOUJICHUFLG = false;
        //0.5秒後に
        setTimeout(function() {
          //効果音
          playSE('kakutoku');
          //2秒後に
          setTimeout(function() {
            //BGM停止
            stopBGM();
            //札取りモードフラグ
            SPOTTORIFLAG = false;
            
            console.log('リザルト遷移直前');                                  
            //リザルトページへ遷移
            document.querySelector('#navigator').pushPage('result.html',{animation: 'fade'});
            //ARを閉じる
            app.wikitudePlugin.close();
          }, 2000);
        }, 500);
      }else if ( 'shippai' == json.action ) {
        //効果音
        //playSha();
        //バイブレーション
        //vibration();
        //0.5秒後に
        setTimeout(function() {
          //ビヨヨーン効果音
          //playBiyoyon();
        }, 500);
      }else{
        alert('ARchitect => PhoneGap ' + url);
      }  
    }
    
    // 受け取ったイベントのDOMを更新する
    /*receivedEvent: function(id) {
      console.log('id:'+ id);
      var parentElement = document.getElementById(id);
      console.log('parentElement:'+ parentElement);
      var listeningElement = parentElement.querySelector('.listening');
      var receivedElement = parentElement.querySelector('.received');
  
      listeningElement.setAttribute('style', 'display:none;');
      receivedElement.setAttribute('style', 'display:block;');
          console.log('Received Event: ' + id);
    }*/
};
  
  
//ARコンテンツへ遷移
function toAR(){
  console.log('toAR start');
  ARFLAG = true;
  //札札取りモードBGM
  stopBGM();
  playBGM('fudatori_bgm');
  console.log('app.wikitudePlugin:'+app.wikitudePlugin);
  app.wikitudePlugin.loadARchitectWorld(
    app.onARExperienceLoadedSuccessful, 
    app.onARExperienceLoadError,
    "www/ar.html",
    [ "geo"],
    {"camera_position": "back"}
  );
}
  
app.initialize();
  

 What information do you need afterwards to solve this problem?

Hi,


When calling loadARchitectWorld is reporting an undefined error, it means that the plugin is not imported properly into the project. If by copying the www folder the plugin is working fine, I would say that importing the plugin manually is missing something in order to have the plugin working.


Regards,


Aitor.

Can you tell me what is wrong with the code I sent you? If it is fire resistant, what other information do you need?

Resolved.


It seems that the "deviceready" event was not working properly due to the code for another plugin.


Thank you for your patience.

Login or Signup to post a comment