You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "abhilashhm (via GitHub)" <gi...@apache.org> on 2023/04/03 19:54:01 UTC

[GitHub] [cordova-android] abhilashhm opened a new issue, #1585: Unable to make any API calls

abhilashhm opened a new issue, #1585:
URL: https://github.com/apache/cordova-android/issues/1585

   # Bug Report
   
   ## Problem
   I am trying to make couple of API calls in the index.html file. I tried fetch, XHR XMLHttpRequest and, Jquery AJAX. They all work fine on the browser. But, once the Android app is built, they don't do anything on the app.
   
   Tried troubleshooting using android studio and I get this error for fetch "cordova android "Uncaught (in promise) TypeError: Failed to fetch""
   
   ### What is expected to happen?
   A simple API call should succeed.
   
   
   ### What does actually happen?
   On the App, it does nothing.
   
   
   ## Information
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   **What I see when I run Cordova requirements is this:**
   
   Requirements check results for android:
   Java JDK: installed 11.0.8
   Android SDK: installed true
   Android target: not installed
   Command failed with exit code 1: avdmanager list target
   Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
           at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
           at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
           at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
           at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
           at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
   Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
           at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
           at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
           at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
           ... 5 more
   Gradle: installed C:\Users\haniyura\.gradle\wrapper\dists\gradle-7.5-bin\f1w0cc9nuo0eivz97x2xlu9sv\gradle-7.5\bin\gradle.BAT
   
   Requirements check results for browser:
   Some of requirements check failed.
   
   But the build does not fail. I am able to emulate the app on phone using 'cordova run android' command.
   
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   ```
   const url = `http://103.12.1.88/camlinwebservice/getstudentdata/8147647778`;
   				
   $.ajax({
   	type: "GET",
   	url: url,
   	success: function (xml) {
   		console.log(xml);
   }, cache: false
   });
   ```
   You can find the complete code here: [index.html](https://github.com/abhilashhm/SchoolAppCamlin/blob/main/www/index.html)
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   Testing on Android 12 phone.
   Cordova Android 11
   No Plugins
   SDK platform - Android 12L (API Level 32)
   SDK tools - 30.0.3, 32.0.0, 33.0.2
   
   
   ### Version information
   <!--
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins (No plugins)
   Other Frameworks: None
   Windows, Android Studio.
   -->
   
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] abhilashhm commented on issue #1585: Unable to make any API calls

Posted by "abhilashhm (via GitHub)" <gi...@apache.org>.
abhilashhm commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1495711337

   Thanks a lot for your response. Appreciate your time.
   It started working randomly. 
   
   I tried adding the block you provided to the config.xml file:
   
   ```
   <?xml version='1.0' encoding='utf-8'?>
   <widget id="com.abhi.camlin" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
       <name>Camlin School</name>
       <description>Camlin School App</description>
       <author email="abhilashhm15@gmail.com" href="#">
           Abhilash H M
       </author>
       <content src="index.html" />
       <allow-intent href="http://*/*" />
       <allow-intent href="https://*/*" />
       <icon src="www/images/school_logo.jpeg" />
       <access origin="*" />
       <allow-navigation href="*" />
       <allow-navigation href="http://*/*" />
       <allow-navigation href="https://*/*" />
       <allow-navigation href="data:*" />
       <preference name="AndroidInsecureFileModeEnabled" value="true" />
       <preference name="scheme" value="https" />
       <preference name="hostname" value="localhost" />
       <platform name="android">
           <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
               <application android:usesCleartextTraffic="true" />
           </edit-config>
       </platform>
   </widget>
   ```
   
   But during Cordova build android, it fails.
   
   ```
   > Task :app:mergeDebugResources FAILED
   
   FAILURE: Build failed with an exception.
   
   * What went wrong:
   Execution failed for task ':app:mergeDebugResources'.
   > A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
      > Resource compilation failed (Failed to compile resource file: C:\Users\haniyura\SchoolAppCamlin\platforms\android\app\src\main\res\xml\config.xml: . Cause: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "android" (for attribute "usesCleartextTraffic")
         at [row,col {unknown-source}]: [18,59]). Check logs for more details.
   
   * Try:
   > Run with --stacktrace option to get the stack trace.
   > Run with --info or --debug option to get more log output.
   > Run with --scan to get full insights.
   
   * Get more help at https://help.gradle.org
   
   Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
   
   You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
   
   See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings
   
   BUILD FAILED in 8s
   43 actionable tasks: 3 executed, 40 up-to-date
   Command failed with exit code 1: C:\Users\haniyura\SchoolAppCamlin\platforms\android\gradlew cdvBuildDebug -b C:\Users\haniyura\SchoolAppCamlin\platforms\android\build.gradle
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek closed issue #1585: Unable to make any API calls

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek closed issue #1585: Unable to make any API calls
URL: https://github.com/apache/cordova-android/issues/1585


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] aaarichter commented on issue #1585: Unable to make any API calls

Posted by "aaarichter (via GitHub)" <gi...@apache.org>.
aaarichter commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1506543536

   thank you for your reply @breautek . It helped a lot.
   
   in https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#android-sdk-tools the `cmdline-tools` should be added as required package. It is missing in the fresh install of the latest Android Studio.
   
   Also the guide suggests adding `$ANDROID_SDK` besides $ANDROID_HOME - I wonder why both are required when they point to the same path 🤷‍♂️ 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek commented on issue #1585: Unable to make any API calls

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1505610800

   > I'm seeing the the exact output when running `cordova requirements` and I'm major confused on how to solve this. Lastest Android Studio is installed, JAVA SKD 11, Gradle.
   > 
   > But https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#requirements-and-support is not really clear and should have a section for all requirements - whats the avdmanager, what is behind those java issues.
   > 
   > Its so frustrating when you fail on a hello world
   
   The OP describes two unrelated issues in their post. For the `cordova requirements` issue regarding `avdmanager`, it's a command line tool for managing AVDs (Android Virtual Devices).
   
   Android SDK ships two versions of this tool, one under `$ANDROID_HOME/tools/bin`, and another at `$ANDROID_HOME/cmdline-tools/<version>/bin`, where `$ANDROID_HOME` is the root folder of the Android SDK directory.
   
   All tools under ` $ANDROID_HOME/tools/bin` are legacy tools and shouldn't be used.
   
   If it prints:
   
   ```
   Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
   ...
   ```
   
   It means you're using the legacy tools. They aren't compatible with Java 11 runtimes. This is likely the result of having `$ANDROID_HOME/tools/bin` in your `PATH` environment variable. If so it should be removed. It should be also checked that `$ANDROID_HOME/cmdline-tools/<version>/bin` is in the `PATH`.
   
   The `<version>` depends on the version of cmdline-tools package you installed. Android Studio's SDK Manager also have the `latest` version that can be installed, which case the path will look like `$ANDROID_HOME/cmdline-tools/latest/bin`. However I'd recommend pinning it to a specific version so that upgrades are intentional to avoid things randomly breaking.
   
   The main issue this ticket describes is relating to HTTP calls, so and given there has been a lack of a response from the OP I'll assume this has been resolved. If you need further assistance on the `avdmanager` situation, please raise a new [Discussion](https://github.com/apache/cordova/discussions) for support, or if you think you have found a bug, you can raise a new [issue](https://github.com/apache/cordova-android/issues).
   
   Thank you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek commented on issue #1585: Unable to make any API calls

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1495931541

   My apologies, my example forgot to include the xml namespace for the `android` tag.
   
   In the root tag, add `xmlns:android="http://schemas.android.com/apk/res/android"` like so:
   
   ```xml
   <?xml version='1.0' encoding='utf-8'?>
   <widget id="com.abhi.camlin" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android>
   ...
   </widget>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek commented on issue #1585: Unable to make any API calls

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1494962795

   If you caught the error so that you can see the actual error message, you can be more confident with that is wrong.
   
   However Android by default will block insecure (non-HTTPs) connections, and based on the information available, that's my best guess.
   
   You can get around that by using:
   
   ```
   <platform name="android">
     <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
         <application android:usesCleartextTraffic="true" />
     </edit-config>
   </platform>
   ```
   
   In your `config.xml`, however for production you should have a real https server to use and that remove the `edit-config` to allow clear text traffic.
   
   Please catch and post the error if you need more help.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] aaarichter commented on issue #1585: Unable to make any API calls

Posted by "aaarichter (via GitHub)" <gi...@apache.org>.
aaarichter commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1506830747

   thanks @breautek for the details explanation and the history behind those env variables 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] aaarichter commented on issue #1585: Unable to make any API calls

Posted by "aaarichter (via GitHub)" <gi...@apache.org>.
aaarichter commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1505592932

   I'm seeing the the exact output when running `cordova requirements` and I'm major confused on how to solve this. Lastest Android Studio is installed, JAVA SKD 11, Gradle.
   
   But https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#requirements-and-support is not really clear and should have a section for all requirements - whats the avdmanager, what is behind those java issues.
   
   Its so frustrating when you fail on a hello world


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] breautek commented on issue #1585: Unable to make any API calls

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1506757088

   > in https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#android-sdk-tools the cmdline-tools should be added as required package. It is missing in the fresh install of the latest Android Studio.
   
   Thanks for the pointing this out. It's documented for the PATH, but it's definitely unclear where cmdline-tools comes from. I'll create an issue in our docs for this.
   
   > Also the guide suggests adding $ANDROID_SDK besides $ANDROID_HOME - I wonder why both are required when they point to the same path man_shrugging
   
   There is some history here. Google/Android team historically used `$ANDROID_HOME` for all their tooling. One day they deprecated this variable and suggested to start using `$ANDROID_SDK_ROOT`. Since then, they've done a 180 and undeprecated `$ANDROID_HOME` and deprecated `$ANDROID_SDK_ROOT`. I suspect because there is a lot of external/third-party tooling (Including Cordova) that really depends on this variable and lots of people raised complaints.
   
   Current versions of Cordova will primarily look for `$ANDROID_SDK_ROOT` and fallback to `$ANDROID_HOME`, hence the 11.x docs suggest using `$ANDROID_SDK_ROOT`. This is however being changed (again) in the next major of cordova-android.
   
   So I'd recommend setting both variables like this in (Unix/Bash Environment):
   
   ```
   export ANDROID_HOME="path/to/android/sdk"
   export ANDROID_SDK_ROOT=$ANDROID_HOME
   ```
   
   I believe android tooling will use `ANDROID_HOME` primarily, and it will check if `ANDROID_SDK_ROOT` is set, and if so it will enforce (potentially by throwing an error) if it's not the same as `ANDROID_HOME`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-android] iamtowbee commented on issue #1585: Unable to make any API calls

Posted by "iamtowbee (via GitHub)" <gi...@apache.org>.
iamtowbee commented on issue #1585:
URL: https://github.com/apache/cordova-android/issues/1585#issuecomment-1732226779

   > > I'm seeing the the exact output when running `cordova requirements` and I'm major confused on how to solve this. Lastest Android Studio is installed, JAVA SKD 11, Gradle.
   > > But https://cordova.apache.org/docs/en/11.x/guide/platforms/android/index.html#requirements-and-support is not really clear and should have a section for all requirements - whats the avdmanager, what is behind those java issues.
   > > Its so frustrating when you fail on a hello world
   > 
   > The OP describes two unrelated issues in their post. For the `cordova requirements` issue regarding `avdmanager`, it's a command line tool for managing AVDs (Android Virtual Devices).
   > 
   > Android SDK ships two versions of this tool, one under `$ANDROID_HOME/tools/bin`, and another at `$ANDROID_HOME/cmdline-tools/<version>/bin`, where `$ANDROID_HOME` is the root folder of the Android SDK directory.
   > 
   > All tools under ` $ANDROID_HOME/tools/bin` are legacy tools and shouldn't be used.
   > 
   > If it prints:
   > 
   > ```
   > Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
   > ...
   > ```
   > 
   > It means you're using the legacy tools. They aren't compatible with Java 11 runtimes. This is likely the result of having `$ANDROID_HOME/tools/bin` in your `PATH` environment variable. If so it should be removed. It should be also checked that `$ANDROID_HOME/cmdline-tools/<version>/bin` is in the `PATH`.
   > 
   > The `<version>` depends on the version of cmdline-tools package you installed. Android Studio's SDK Manager also have the `latest` version that can be installed, which case the path will look like `$ANDROID_HOME/cmdline-tools/latest/bin`. However I'd recommend pinning it to a specific version so that upgrades are intentional to avoid things randomly breaking.
   > 
   > The main issue this ticket describes is relating to HTTP calls, so and given there has been a lack of a response from the OP I'll assume this has been resolved. If you need further assistance on the `avdmanager` situation, please raise a new [Discussion](https://github.com/apache/cordova/discussions) for support, or if you think you have found a bug, you can raise a new [issue](https://github.com/apache/cordova-android/issues).
   > 
   > Thank you.
   
   This helped me solve the target not found error, thanks. Now I'm getting a different error: Please set the JAVA_HOME variable in your environment to match the location of your Java installation. Please help.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org