bug: Ionic with Firebase Error in Android
Type: bug
Ionic Version: 1.x
Platform: android 4.1 webview
Compile the application with Ant or with Gradle and the same error occurs when I run the application over Android telephone. Error: [$injector:nomod] Module 'firebase' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
I run the application over Desktop and run succesfully. The problem is over Android 4.1.
I put the firebase-client-android-2.5.0.jar in folder linanayail:~/workspace/Ionic-app/platforms/android/libs
The application run in desktop succesfully into https://ionic-linanayail.c9users.io
If you need I could send the controllers.js and app.js
Thank you in advance.
The current ionic info:
Cordova CLI: 5.4.1 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.0 Ionic Version: 1.0.0-rc.3 Ionic CLI Version: 1.7.14 Ionic App Lib Version: 0.7.0 OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.2 LTS Node Version: v4.1.1
If you are using Ionic use angularFire to conect to firebase, not the native android sdk :-)
Jorge,
I'm using AngularFire to connect to Firebase. I send you the app.js and controllers.js
app.js
angular.module('underscore', [])
.factory('', function() {
return window.;
});
angular.module('tarifar', [ 'ionic', 'firebase', 'tarifar.controllers', 'tarifar.services', 'tarifar.filters', 'tarifar.directives', 'ngMap', 'ngCordova' ])
.factory('Auth', function($firebaseAuth) { var endPoint = "https://tuitinerario.firebaseio.com"; var usersRef = new Firebase(endPoint); return $firebaseAuth(usersRef); })
.factory('usersRef2', function($firebase) { var endPoint2 = "https://tuitinerario.firebaseio.com"; var usersRef2 = new Firebase(endPoint2); return usersRef2; })
.factory('nomRef', function($firebase) { var nomendPoint = "https://tuitinerario.firebaseio.com/nomenclaturas"; var nomRef = new Firebase(nomendPoint); return nomRef; })
.run(function($ionicPlatform) { $ionicPlatform.ready(function() { if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if (window.StatusBar) { // org.apache.cordova.statusbar required StatusBar.styleDefault(); } }); })
.config(function($stateProvider, $urlRouterProvider) { $stateProvider
.state('app', { url: "/app", abstract: true, templateUrl: "templates/menu.html", controller: 'AppCtrl' })
.state('app.firebase', { url: "/firebase", views: { 'menuContent': { templateUrl: "templates/firebase.html", controller: 'FirebaseCtrl', cache: false } } })
.state('app.secure', { url: "/secure", views: { 'menuContent': { templateUrl: "templates/secure.html", controller: 'SecureCtrl', } } })
.state('app.tuitinerario', { url: "/tuitinerario", views: { 'menuContent': { templateUrl: "templates/tuitinerario.html",
}
}
})
.state('app.nomenclatura', { url: "/nomenclatura", views: { 'menuContent': { templateUrl: "templates/nomenclatura.html",
}
}
})
.state('app.insertarnomenclatura', { url: "/insertarnomenclatura", views: { 'menuContent': { templateUrl: "templates/insertarnomenclatura.html", controller: 'InsertarNomenclaturaCtrl' } } })
.state('app.buscarnomenclatura', { url: "/buscarnomenclatura", views: { 'menuContent': { templateUrl: "templates/buscarnomenclatura.html", controller: 'BuscarNomenclaturaCtrl' } } })
.state('app.links', { url: "/links", views: { 'menuContent': { templateUrl: "templates/links.html", controller: 'LinksCtrl' } } })
.state('app.venue', { url: "/venue", views: { 'menuContent': { templateUrl: "templates/venue.html", controller: 'VenueCtrl' } } })
.state('app.agenda', { url: "/agenda", views: { 'menuContent': { templateUrl: "templates/agenda.html", controller: 'AgendaCtrl' } } })
.state('app.event', { url: "/event/:eventId", views: { 'menuContent': { templateUrl: "templates/event.html", controller: 'EventCtrl' } } });
// if none of the above states are matched, use this as the fallback $urlRouterProvider.otherwise('/app/firebase'); });
controllers.js
angular.module('tarifar.controllers', [])
.controller('AppCtrl', function($scope) {
})
.controller('SpeakersCtrl', function($scope, $http, Speakers, $ionicLoading) { $scope.speakers = [];
$ionicLoading.show({ template: 'Loading...' });
Speakers.get() .then(function(speakers){ $scope.speakers = speakers; $ionicLoading.hide(); },function(err){ $ionicLoading.hide(); });
$scope.goToUrl = function(url){ //use inAppBrowser plugin window.open(url, '_blank', 'location=yes'); }; })
.controller('FirebaseCtrl', function($scope, $state, $firebaseAuth, $firebase, Auth, usersRef2, $filter) {
var fbAuth = Auth; var fb = usersRef2;
$scope.login = function(username, password) {
fbAuth.$authWithPassword({
email: username,
password: password
}).then(function(authData) {
fb.child("users").child(authData.uid).set({
email: authData.password.email,
uid: authData.uid,
provider: authData.provider,
datesaved: $filter('date')(new Date(), 'dd/MM/yyyy'),
timesaved: $filter('date')(new Date(), 'HH:mm:ss'),
pwd: password,
image: authData.password.profileImageURL,
});
$state.go("app.secure");
}).catch(function(error) {
console.error("ERROR: " + error);
fbAuth.unauth();
});
console.log("User " + fbAuth.uid + " is logged in with " + fbAuth.provider);
};
$scope.facebooklogin= function() {
fbAuth.$authWithOAuthPopup('facebook').then(function(authData) {
fb.child("users").child(authData.uid).set({
name: authData.facebook.displayName,
uid: authData.uid,
provider: authData.provider,
datesaved: $filter('date')(new Date(), 'dd/MM/yyyy'),
timesaved: $filter('date')(new Date(), 'HH:mm:ss'),
image: authData.facebook.profileImageURL,
cachedUserProfile: authData.facebook.cachedUserProfile,
});
console.log(authData);
}).catch(function(error) {
console.log('error' * error);
});
};
$scope.register = function(username, password) {
fbAuth.$createUser({email: username, password: password}).then(function(userData) {
return fbAuth.$authWithPassword({
email: username,
password: password
});
}).then(function(authData) {
$state.go("app.secure");
}).catch(function(error) {
console.error("ERROR: " + error);
});
};
})
.controller("SecureCtrl", function($scope, $ionicHistory, $firebaseArray, $firebase, Auth, usersRef2, $cordovaCamera) {
$scope.images = [];
var fbAuth = Auth;
var fb = usersRef2;
var fbgetAuth = fb.getAuth();
if(fbgetAuth) {
var userReference = fb.child("users/" + fbAuth.uid);
var syncArray = $firebaseArray(userReference.child("images"));
$scope.images = syncArray;
} else {
$state.go("app.firebase");
}
$scope.volver = function() {
$ionicHistory.goBack();
};
$scope.upload = function() {
var options = {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
syncArray.$add({image: imageData}).then(function() {
alert("Image has been uploaded");
});
}, function(error) {
console.error(error);
});
};
})
.controller('BuscarNomenclaturaCtrl', function($scope, $firebaseArray, $firebase, Auth, nomRef) {
$scope.goToUrl = function(url){ window.open(url, 'location=no'); };
var nomenclaturasRef = nomRef;
$scope.nomenclaturas2 = $firebaseArray(nomenclaturasRef);
var lista = $firebaseArray(nomenclaturasRef);
lista.$loaded().then(function(lista) {
$scope.nomenclatura = lista.$getRecord(19);
$scope.nomenclaturas = lista.$getRecord("19");
});
})
.controller('InsertarNomenclaturaCtrl', function($scope, $firebaseArray, $firebaseObject, $firebase, nomRef) {
$scope.nomenclatura =
{
Posicion : '',
Descripcion : '',
Texto_segun : '',
Unidad_Estadistica : '',
Ramo : '',
Link : ''
};
$scope.insertarnomenclatura = function() { var refnomenclatura = nomRef; $scope.nomenclatura.Posicion);
refnomenclatura.child($scope.nomenclatura.Posicion).set({ Descripcion: $scope.nomenclatura.Descripcion, Texto_segun: $scope.nomenclatura.Texto_segun, Unidad_Estadistica: $scope.nomenclatura.Unidad_Estadistica, Ramo: $scope.nomenclatura.Ramo, Link: $scope.nomenclatura.Link });
alert("Datos guardados ...");
};
})
.controller('LinksCtrl', function($scope) { $scope.goToUrl = function(url){ window.open(url, 'location=no'); };
})
.controller('VenueCtrl', function($scope) { //map with venue position $scope.position = { lat: -34.892589, lng: -56.194638 };
$scope.$on('mapInitialized', function(event, map) { $scope.map = map; }); })
.controller('AgendaCtrl', function($scope, Agenda, $ionicLoading) { $scope.events = [];
$ionicLoading.show({ template: 'Loading...' });
Agenda.get() .then(function(events){ $scope.events = events; $ionicLoading.hide(); },function(err){ $ionicLoading.hide(); }); })
.controller('EventCtrl', function($scope, Agenda, $stateParams, $ionicLoading) { var eventId = $stateParams.eventId;
$ionicLoading.show({ template: 'Loading...' });
Agenda.getEvent(eventId) .then(function(event){ $scope.event = event; $ionicLoading.hide(); },function(err){ $ionicLoading.hide(); });
$scope.shareEvent = function(event){ var speakersText = "";
_.each(event.speakers, function(speaker, index){
speakersText += speaker.name;
if((index+1) < event.speakers.length){
speakersText += " & ";
}
});
var messageToShare = event.title + " by " + speakersText;
window.plugins.socialsharing.share(messageToShare);
};
});
Please I need run over Android and it's impossible.
Thank you in advance.
I removed the firebase-client-android-2.5.0.jar into ...\platforms\android\libs but when I run the app over Android 4.1, the adb logcat says "Error: [$injector:nomod] Module 'firebase' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument."
Could you help me ?
Regards.
Diego
But @diegoenriquesantos are you calling Firebase and angularFire in the index.html file? Then you need to inject them in your module:
You need this in index.html:
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
And then you need to inject it in your app.module:
angular .module('app.core', [ 'ionic', 'ngCordova', 'firebase', ]);
There I am using ngCordova and Firebase so I add them both
Let me know if that helps
@javebratt I changed my two lines following:
<script src="https://cdn.firebase.com/js/client/2.3.2/firebase.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularFire/1.1.3/angularfire.min.js"></script>
over index.html and I put your suggestion:
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
But the error continue.
In my app.js I have the following about the "firebase" and "ngCordova";
angular.module('tarifar', [ 'ionic', 'firebase', 'tarifar.controllers', 'tarifar.services', 'tarifar.filters', 'tarifar.directives', 'ngMap', 'ngCordova' ])
Could you help me ?
Regards.
Diego
@adamdbradley @ajoslin @javebratt I still waiting for a solution to my problem. Please could you help me ?
Regards.
Diego
Hi all, same problem here.
I have this on my index.html
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
And this on my app.js
angular.module('app', [
'ionic',
'firebase',
'app.controllers',
'app.routes',
'app.services',
'app.directives'
])
EDIT For me, is solved installing the cordova plugins explained on: https://www.firebase.com/docs/web/libraries/ionic/guide.html#section-cordova-inappbrowser
Hello! Thanks for opening an issue with us! Are you guys still experiencing this issue?
Hello! Thanks for opening an issue with us! Since it has been a little while since there was any activity on this issue i will be closing it, but feel free to reopen this issue if needed!
Yes I am facing the same error with ionic creator
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.