Javascript of apk built by cordova CLI doesn't work on emulator/device

377 Views Asked by At

I have started to learn PhoneGap/Cordova to create app for mobile devices.

I created test app (cordova create) and added javascript file with simple function.

file test1.js:

function doalert() {
    alert("Test1 alert!");
}

Then I put button into generaten index.html + included mentioned js script file:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>rth Test1</title>

        <script type="text/javascript" src="js/test1.js"></script>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>

        <button type="button" onclick="doalert()">Alert</button>
    </body>
</html>

As you can see, button should invoke the doalert() function, which displays alert.

Here is the problem:
If I build this project into android application (apk) and install it on emulator or on my device, it doesn't work as expected. Application launches and shows "Device is ready". But, tapping on button doesn't do anything (looks like the JavaScript function is not called).

If I run it from browser (Firefox) or if I use PhoneGap server - client applications, then everything works fine.

I have checked inside of apk, and all files seems to be in place.

Using below software versions:

Android: 4.4.4
Cordova: 4.0.0
0

There are 0 best solutions below