Apache Cordova for android do not load resources - android

I have created an Angular 2 application and I'm looking for creating an Android application with Apache Cordova. When I load the application in a Marshmallow emulator, the application does not load any of the declared resources. If I use the browser plugin it works as expected. Using Chrome to inspect the device's console reveals the following output.
Chrome console output:
If I run the Cordova initial sample it works in the same Android emulator so it has to be a problem with the sources. The code can be checked in the Github repository. The application is in the www directory, for testing it is necessary to add the android platform.
$ cordova platform add android
$ cordova run android
I can not found an answer for this problem:
The resources looks fine - discard file path issues.
The browser plugin works (Chrome) - discard application errors and security policies.
The cordova sample works as expected for Android - discard environment errors.
Please, does anyone knows what is the problem with this setup?

I have found the root cause. The problem is that by using the angular-cli tool, the tag <base href="/"> is being added automatically. According to the tag documentation, it serves a base to resolve all the document's relative URLs.
For this use case, removing the base tag or configuring it to a valid value like <base href="/android_asset/www/"> fixes the problems. As I do not use routing features (yet) I feel more confortable removing it or setting a value like <base href="."/> that it's suitable for more platforms builds.

Have you tried modifying Content-Security-Policy?
Or how about modifying 'allow-intent' in config.xml?
When I was having resources issue, these were helping.

Related

Cordova Android CORS crypt-file plugin

I am currently developing an Android application with Cordova and am trying to use the following plugin, to encrypt the source files.
https://github.com/tkyaji/cordova-plugin-crypt-file
While iOS is working fine, on Android I get the following error.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
Without the plugin, everything is working fine. I do have the CSP set and am also using the whitelist plugin where I have added localhost in my config.xml. I have searched for quite a while now, but all seem to be solving the problem with whitelisting, which is not working for me.
I am currently using Cordova 5.4.1
Any help/idea would be appreciated.
Best regards
Runned into the same problem, solved this by allowing localhost request on the server for that specific action.
header("Access-Control-Allow-Origin: http://localhost");
See also the github issue: https://github.com/tkyaji/cordova-plugin-crypt-file/issues/4

Cross-origin Resource Sharing in Android via Ionic and Cordova

My issue is similar to this question.
I have an HTML5-based Android app. It is wrapped in Cordova, and built using the Ionic Framework. When launched, the app loads an index.html file, which is located locally on the device and makes a cross-origin resource request. It therefore does not load for Android API 18 and higher.
The workaround to this restriction is to enable the setAllowUniversalAccessFromFileURLs setting. Given that my project is built using the Ionic Framework, what would be the correct way to enable this flag? Would I necessarily need to go into the Android project to enable the flag, or is there a cleaner way to do it via a settings file?
I have inherited this project and have very little experience with Ionic, Cordova, and HTML5, therefore any detail would be greatly appreciated. In the question above, the solution was to update to Cordova 2.8.1. I am running Cordova 5.1.1. and still experience the problem.
Can be a origin problem try to whitelist your remote domain.
Read this http://docs.phonegap.com/en/4.0.0/guide_appdev_whitelist_index.md.html

PhoneGap Plugin (BluetoothSerial) doesn't work

I'd like to create a PhoneGap App and open a connection to another device through Bluetooth (https://github.com/don/BluetoothSerial). I started with the sample projects but nothing seems to happen with my settings, no events are triggered / console shows nothing.
I'm new to Phonegap and after struggling for days with installing NodeJs, Cordova (4.0.0), Phonegap (3.6.0-0.21.19), Ant, getting new Java JDK (1.7.0_71), updating Android (23, target here is Android API19) I can build and run Android apps. I followed http://www.pycode.com/android/creating-a-phonegap-cordova-3.0-app-in-eclipse.html as installation guide.
Nevertheless I couldn't build the jar file for Cordova (Target "jar" is not found), paths are set correctly. I searched online but the existing posts didn't help. Actually I found out that it's better to just use the CordovaApp-CordovaLib as a library, so I used this instead. Anyway it seems like I can't use any plugins at the moment (added in config.xml and gave Bluetooth permission in AndroidManifest.xml). I'm not even sure if this is the problem here.
Seems like many people are struggling with Phonegap and I hope somebody experienced the same issues and can help.. Thanks in advance!
Update
Figured out that the onDeviceReady method wasn't called at all. Checked for cordova.js (don't just use any!) and copied it into my C:\ProjectPath\platforms\android\assets\www folder.
Quite embarrassing, maybe that's why nobody's answered. I used the PhoneGap Developer App - of course this couldn't work. Use cordova build to build apk and test it on device..

cordova/ionic app crashes after startup on older versions of android

The app runs fine on ios and android 4.4+ and lollipop. However on older android versions (e.g 4.1.1) the app crashes directly after I start it.
Full stacktrace her is the logcat stack trace on such a tablet (Not sure which piece I had to copy) here the link
The exception is rather vague.
Thank you!
android 4.4+ use chromium as default browser, while any version below use android-browser.
It is much weaker browser. If your app runs perfectly in ios or android-4.4, then this could be the reason.
one work around is to use crosswalk by intel. cordova-crosswalk. Read More.
Basically it wraps your app in chromium browser, and package it as android app.
when the app run, it run chromium first( instead of android-browser) and then the code inside of it.
noticable cons is extra 15-20mb to your app filesize.
to migrate from cordova to crosswalk cordova. read More.
In the recent update, it seems there is new command to migrate app automatically.
But what i did previously, was to do manual migration (by copy paste).
> few Tips if you do manually:
> 1. create new crosswalk project from cli
> 2. copy files in **www folder in cordova** to **www folder in crosswalk**
> EXCLUDING one file : config.xml
> 3. Install your plugin manually. Read More: http://goo.gl/wF4CmD.
> 4. in crosswalk,set the config.xml manually.

Cordova/Phonegap hybrid android app on blackberry: can't access asset file

I've created a hybrid HTML5 Android app based on Cordova/Phonegap, that i want to deploy on Blackberry using the Android app converter.
My startup html file is located in the assets folder of my Android app. After deploying my app on Blackberry 10 simulator and starting it, i'm getting an application error,
saying that the protocol isn't supported.
I changed my url to "asset:///www/index.html" already.
What can i do to fix that?
Thanks, Stephan
I located my problem and solved it:
I was using an older version of Phonegap in conjunction with the now deprecated plugin.xml. I switched to config.xml, using the access origin and content source tag, and I changed my startup url to file:///android_asset/www/index.html, which now works both with Android and Blackberry.

Categories

Resources