Updating an Android project via CLI to include two downloaded SDK libraries - android

I am attempting to add a main expansion file to my Cordova Android project. Before I can go further, I need to link up two libraries with the project. I am stuck on the following instructions in http://developer.android.com/google/play/expansion-files.html#AboutLibraries:
from a command line, update your project to include the libraries:
Change directories to the /tools/ directory.
Execute android update project with the --library option to add both
the LVL and the Downloader Library to your project. For example:
android update project --path ~/Android/MyApp \
--library ~/android_sdk/extras/google/market_licensing \
--library ~/android_sdk/extras/google/market_apk_expansion/downloader_library
I formatted the first part to match my system (my best understanding of what to do):
android update project --path ~/Documents/AndroidApps/apkext --library ~/Developer/android-sdk-mac_x86/extras/google/market_licensing
I got this error message:
Error: /Users/Steve/Documents/AndroidApps/apkext is not a valid project (AndroidManifest.xml not found).
I don't know how to go further. This being a Cordova app, the AndroidManifest.xml file resides in apkext/platforms/android/ and the apk build for the project is in apkext/platforms/android/ant-build
I have already successfully downloaded the two libraries asked for and they are in the tools/ folder in the path indicated. Am I applying the instructions wrong?

I think you're following instructions intended for a native android application and your project is a multiplatform cordova app.
Either you only want to focus on the android platform and don't want to use cordova CLI anymore (so you'll have to install plugins manually or using plugman) or you want to use the CLI and continue with the cordova project.
In the first case, just focus on the paltforms/adroid part of the project and forget all the rest.
paltforms/adroid contains the android native app.
So for example use
android update project --path ~/Documents/AndroidApps/apkext/platforms/android --library ~/Developer/android-sdk-mac_x86/extras/google/market_licensing
should work better.
In the other case, if you want to keep using the cordova cli, you should build a cordova plugin that would be composed of your libraries, a java class and javascript to call the native code from your cordova app. In that case you just have to configure the plugin to put the libraries in the libs folder.
Anyway, even if you're only interested in android, I think you will have to make a plugin if you want to do something with your libraries?

Related

Embedding cordova application on Android native application

What I'm trying to do is embed a cordova application into a native android application.
It seems to me that the documentation is out of date or not clear about the steps that needs to be done.
Documentation:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html
I am at the point that I can't create the .jar file for the following reasons.
I don't have a /framework directory in my root project directory or in platforms/android
Cordova seems to be using gradle instead of ant for building the android project. I can't find a build.xml anywhere in the android project.
My Cordova version: 8.0.0
As as followup question, I expect this .jar file will also contain the plugins that the cordova project depends on, correct?

How do I build a Cordova 8.x cordova.jar to include in existing Android app?

I this documentation:
Cordova documentation
I cloned the latest Cordova here: https://github.com/apache/cordova-android
But when I run "ant jar" as described in the documentation, I get this error:
cordova-android-master/framework/build.xml:124: Cannot find
/Users/neigaard/Library/Android/sdk/tools/ant/build.xml imported from
/Users/me/cordova-android-master/framework/build.xml
Google say that is because ant/build.xml was removed from Android SDK. I found a post saying that I should download a old Android SDK tools and replace my SDK tools folder with that, but I rely on my Android SDK to be working and up to date.
Is there no way to build the Cordova Android jar without an outdated Android SDK or is there somewhere I can download a pre-built jar or is there another way to integrate Cordova into a existing Android app?
You don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:
implementation 'org.apache.cordova:framework:7.1.0'
Tutorial cordova.apache.org/docs/en/latest/guide/platforms/android/… looks outdated. If you just want to embed a cordova webview you don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:
implementation 'org.apache.cordova:framework:7.1.0'
However if you want to create jar through ant then you don't required to use complete outdated Android SDK.You have to just place ant/build.xml in tools folder.
Below are the steps to create corodva.x.x.x.jar on Windows
Step-1 Download Android tool package from below location:
https://dl.google.com/android/repository/tools_r25.2.5-windows.zip
Step-2 Copy ant folder to
C:\Users\xxxx\AppData\Local\Android\sdk\tools
Step-3 Install Cordova using npm
npm install -g cordova
You can install specific version of cordova using cordova#version.
Step-4 Go to below location and copy your local.properties from your android project:
C:\Users\xxxxx\.cordova\lib\npm_cache\cordova-android\x.x.xx\package\framework
Step-5 Navigate to the Android package's /framework directory and run ant jar.
It creates the Cordova .jar file, formed as /framework/cordova-x.x.x.jar
FYI: It is recommended to refer the cordova requirements-and-support https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support

Cannot update project from terminal in Android

I am developing an Android project. In my project, I need to do OCR. So found this tutorial http://www.codeproject.com/Tips/840623/Android-Character-Recognition. I am trying to follow that tutorial. But I am having problems with set up, especially with updating project from terminal (tess-two folder). See what I have done below.
I downloaded tess-two from this link
https://github.com/rmtheis/tess-two/
Then I installed android NDK to build that project
I set environment variable under PATH
Then I run below command in tess two folder from terminal
ndk-build //this took around 30 minutes. I closed command windows after successful built
Then I run this command
android update project --path C:\tess-two-master\tess-two
The problem starts when I run that command because I cannot run android command from terminal. So I found solution from Stack Overflow. I needed to set ANDROID_HOME and environments variable under PATH. Then I tested "android" command and it is working.
Then I run this command again
android update project --path C:\tess-two-master\tess-two
This time, it is giving me this error
How can I solve this error? Why my update command is not working? What is wrong with my code? I am using Windows 64 OS.
This is another way. Installing using Grandle
I tried another way to install tess-two. I installed using Gradle like this according to documentation. But I cannot access to TessDataManager because it cannot be found in project.
Gradle
dependencies {
compile 'com.rmtheis:tess-two:6.0.2'
}
This is error
As you can see, I cannot access to TessDataManager class. How can I import that class?
The tess-two project has been updated to include a pre-compliled AAR that can be incorporated into your app by editing your app's build.gradle file.
This means that you can skip the steps of importing/compiling the library yourself, and follow the usage instructions on the tess-two project. After following the usage instructions, you'll be able to refer to the tess-two classes -- including the TessBaseAPI class -- directly from your project.

Cordova 3.3.x - Android CordovaLib

When was the cordova.jar file removed from Cordova and replaced with CordovaLib? I was previously running Cordova 3.1.0-0.1.0.
Today I have upgraded to Cordova 3.3.0 (which was quite a headache, but I've completed the upgrade) and I've noticed a difference in my Android project structure: Cordova has created my project (with what I've named it) and it has also created -CordovaLibs.
Is this right? I know iOS it does this - but not Android (as I say, usually a JAR is added).
It's introduced in 3.3, had me baffled too.
Cordova 3.3 release notes:
http://cordova.apache.org/announcements/2013/12/16/cordova-330.html
CB-5232 Change create script to use Cordova as a Library Project
instead of a .jar
To generate file cordova3.3.0.jar, just follow these steps bellow:
Open your cmd, and go to the root folder where Cordova is installed:
$ cd ~/.cordova/lib/android/cordova/3.3.0/framework
Run the following command, notice the trailing dot
$ android update project -p .
Use ant to generate file jar. Be sure you have configure PATH for
$ ant jar
Now, you can copy file cordova3.3.0.jar to libs directory and import to your project. Hope it's helpful

How do I build an Android project using Ant? (IntelliJ IDE)

I've a project in the IntelliJ IDEA IDE and I want to set up a parallel, production Ant build process that I can extend over time.
I have used IntelliJ's feature to create an Ant build file, and it is on the Build menu, so the Ant build process is running, and working within the IDE. All good.
But the Ant script IntelliJ has created is only compiling to class files, and is not doing a full Android build process through to an APK (as far as I can tell).
Can you point me towards a reference source (or an example) to help me understand how to get an ANT script doing a full build of an Android project?
If you know, would also be v useful to know how to then extend it to include Proguard, production signing, and inserting the production Maps key :)
Use this as a starting point:
http://developer.android.com/guide/developing/other-ide.html
I don't know IntelliJ but I shoudn't be very hard to create an ant file with the most frequent commands you need.
UPDATE:
run the following command:
android create project --target 8 --name "MyFirstProject" --path /path/to/project --activity StartingActivity --package net.sample.package
This will create a project structure. This includes a build.xml file that contains targets to build the project.
To build the application, in the root folder (/path/to/project/) run:
ant debug
It should compile your application.
You may have to install or configure ant before this works correctly but you should be able to figure it out by yourself! :)
(All the info is in the link I posted earlier)
It's pretty well described in SDK documentation. Just 3 steps to make it work:
Assuming you have been developing your activity for a while with such powerful thing as IntelliJ Idea. So as Ollie mentioned in comment you don't have to create android project from scratch. Run in command line:
android update project --path "Path to your project" --target "android-X"
where X is API level
After step one build.xml was created automatically. Now you open IntelliJ, go to ant build panel and add that build.xml.
The important step is to open properties of created task and add debug OR release to command line at execution tab.
Now you can run target and enjoy the result. It will take some more efforts to compile into signed release.
Note: your existing project structure should match to android project. Please review documentation. E.g. I had external library put in "lib" subfolder and I managed it to work only after renaming "lib" to "libs"

Categories

Resources