How to create an Android Studio module in command line? - android

I'm trying to create a Bash script to automate the creation of some projects and modules to be used by Android Studio later. However, I can only find how to create projects using the command line, not modules:
android create project --gradle --gradle-version 1.5.0 --target "${BASE_API}" --name "${PROJECT_NAME}" --path "${PROJECT_NAME}" --activity DummyActivity --package it.doesnt.matter
How can I create a module inside the project created above using a Bash command?

A module is mostly just a directory of files. So:
Create a directory (mkdir yourModule)
Put whatever files you want in this directory, such as build.gradle
Script a solution to edit the settings.gradle file and add your module to the list of modules

Related

How to build OpenCv with extra contrib modules

I am trying to build OpenCV to include OpenCV contrib modules which is in a repository. I am following the instructions in this link, but i could not understand the cmd commands which is i mentioned in the section titled "cmd commands" as follows.
cmd commands:
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules
<opencv_source_directory>
$ make -j5
here are my attempts to get the cmd commands as mentioned above running:
1-concerning the opencv_build_directory: i just created it by myself and named it 'build' as shown in the image in the section titled "OpenCV3.0.0 source"
2-concerning the opencv_source_directory: i think it should be "OpenCV-android-sdk" as shown in the image section titled "OpenCV3.0.0 source"
3- for the cmd command '$ cd ' i set it as follows:
c:\xxxx\libs\OpenCV-3.0.0-android-sdk-1\OpenCV-android-sdk\build>
4- for the cmd command '$ cmake -DOPENCV_EXTRA_MODULES_PATH=/modules' iset it as follows:
cmake -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-master/modules OpenCV-
android-sdk
the entire command i type in the cmd is:
c:\xxxx\libs\OpenCV-3.0.0-android-sdk-1\OpenCV-android-
sdk\build>cmake -DOPENCV_EXTRA_MODULES_PATH=opencv_contrib-
master/modules OpenCV-android-sdk
but after running it, i get:
CMake Error: The source directory "C:/xxxx/libs/OpenCV-3.0.0-
android-sdk-1/OpenCV-android-sdk/build/OpenCV-android-sdk" does not
exist.
Specify --help for usage, or press the help button on the CMake GUI.
please help me to build the path correctly as stated in the linke mentioned
note:
I am trying to install opencv contrib modules on android through android Studio
OpenCV3.0.0 source
OpenCV-contrib source:

create android project with gradle from command line deprecated?

I am trying to create android project with gradle from command line using this command:
android create project \
--target android-23 \
--name HelloWorld \
--path HelloWorld/ \
--activity MainActivity \
--package com.example.helloworld \
--gradle \
--gradle-version 1.3.0
Project structure was successfully generated but when I try to run gradlew assembleDebug I get:
A problem occurred evaluating root project 'HelloWorld'.
> Could not create plugin of type 'AppPlugin'.
I was traversing google for half of day and finally I found that usage of gradle in android create project is (probably) deprecated:
https://code.google.com/p/android/issues/detail?id=160032
Are there any supported methods (that are clean, no hacks) to achieve the goal (in command line)?
As instructed here:
http://eqdn.tech/android-development-on-the-command-line/
You can still use "android create project", but will need to adjust the results manually a little bit afterwards. Essentially changing in gradle/wrapper/gradle-wrapper.properties this:
distributionUrl=http://services.gradle.org/distributions/gradle-1.12-all.zip
To this:
distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip
And changing "runProguard false" to "minifyEnabled true" in build.gradle.

Android project and Gradle: assemble a single module

I have an Android Studio project that contains several sub-projects (aka: modules).
I would like to build some of these sub-projects from the command line.
I read on the Android dev guide that you can build your project by simply running
gradlew.bat assembleDebug
from the command line, however this always builds the entire project (all the modules)
I just want to assemble a single module, how do I do that?
Another way to do this is:
gradlew.bat :myModule:assembleDebug
https://stackoverflow.com/a/16987319/1807627
gradlew.bat assembleDebug -a -b path/to/module/build.gradle
-a only builds the component and does not rebuild its dependencies
Use -b to specify another Gradle build file. In this case, the module's instead of the top-level build.gradle.
If you weren't using the Gradle wrapper, you could alternatively just cd to the module directory and run gradle assembleDebug -a there.

Android studio: start project from command line

I have read a helpfull tread however there is some things that are missing. I can create project from command line
android create project --gradle --gradle-version 0.12.2 \
--package com.test.test \
--activity TestActivity \
--target 1 \
--path AutoAndroidApp \
However, this does not create an identical structure as if I would create a project with the android studio. For example from GUI application is put in app folder, also there is build forlder and other differences.
Is there a way to actually reproduce the creation of the project from a command line?

Build application from command line

I'm trying to build an apk file from command line. I created a sample project usng the following command:
android create project --target 1 --name MyApp --path ./MyProject --activity MyActivity --package com.example.myapp
Which created the following structure:
/bin
/res
/src
/libs
AndroidManifest.xml
ant.properties
build.xml
local.properties
proguard-project.txt
project.properties
Now when I try to build the project, I get:
$ gradle build
gradle will not execute and completion _gradle exists.
I couldn't find any info on this error, so I ran:
$ _gradle build
_arguments:comparguments:312: can only be called from completion function
user has logged on pts/7 from :0.0.
Any hints on what am I doing wrong? Thanks!
android create project creates project in structure expected by Eclipse, not gradle based (Android Studio) projects.
I was able to build the apk using the following lines:
ant debug
adb install bin/HelloWorld-debug.apk

Categories

Resources