Add dynamic feature module in a Eclipse Style Android project - android

I am trying to add dynamic feature module in my project. It was previously an Eclipse project so the structure is different from the Android Studio structure. The main application is in the root directory, not an independent module.
The project structure as follow:
/Project Root
Project Root Files
+Module1
+Dynamic Module
I want to add a dynamic feature module in the project, so I need to add the root project as the dependency of the dynamic module. Is there a way that I can do this? In the dynamic module build.gradle file, I tried ':Root' and ':', both did not work. Gradle said it could not resolve the root project.

Even I faced the above issue and was able to resolve it by referring the base module in the dependency module with the below approach.
dependencies {
implementation project(':')
}
If the base module is in the root of the project, one should refer the base module in the dependency module with the ":" symbol.

Using a project structure that gradle can deal with is the important bit here.
You can migrate the project Root to a different folder.
By convention that has been app.
You then can refer to it from dependent projects as :app.
The project structure would be then something like this:
.
├── build.gradle
├── app
│ ├── build.gradle
│ └── src
├── moduleA
│ ├── build.gradle
│ └── src
├── moduleB
│ ├── build.gradle
│ └── src

Related

CMake FindPackage fails for custom built boost libraries

I am trying to build a native Android project that requires Boost library. I have built Boost for the platforms I am targeting using this git project. But for some reason find_package() for Boost fails to find the Boost header paths
Below is the project structure and for the Android app, and location where I have placed the Boost library.
android_app
├── src
│ └──<folder>
│ └──<folder>
│ └──CMakeLists.txt
└── lib
└── boost_armeabi-v7a
├── include
│ └── boost_1_68_0
│ └──boost
│ ├──align.hpp
│ ├──......
│ └──config.hpp
└── lib
├──libboost_atomic.a
├──......
└──libboost_wserialization.a
In the CMake file I have configured like this
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_NO_BOOST_CMAKE ON)
set(LOCAL_LIB_DIR "${PROJECT_SOURCE_DIR}/../../../lib")
set(Boost_ADDITIONAL_VERSIONS "1.68.0")
set(BOOST_INCLUDEDIR "${LOCAL_LIB_DIR}/boost_${ANDROID_ABI}/include")
set(BOOST_LIBRARYDIR "${LOCAL_LIB_DIR}/boost_${ANDROID_ABI}/lib")
find_package(Boost REQUIRED)
Below error is the error iam getting with find_package.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.
I added some message statements and finally narrowed down to this piece of code in the FindBoost CMake file (3.10.2) installed from Android Studio
find_path(Boost_INCLUDE_DIR
NAMES boost/config.hpp
HINTS ${_boost_INCLUDE_SEARCH_DIRS}
PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
)
Dumping there variables, one of the combination for {_boost_INCLUDE_SEARCH_DIRS}/{_boost_PATH_SUFFIXES} should be valid for my path, but after this executes, Boost_INCLUDE_DIR is set as NOTFOUND. I have no idea why this fails.
One of the _boost_INCLUDE_SEARCH_DIRS value is /home/<user>/<path-to-repo>/app/lib/boost_armeabi-v7a/include and one of value in PATH_SUFFIXES is boost_1_68_0. Can some one help me figure out why this is failing?

iOS/ Android app folder structure for React-Native app

I'm creating a React-native app which I'll integrate into iOS/Android app(already created). Can you please suggest a good way of folder structure(especially React-Native).
I really like this way to structure an Project:
── app
├── components
├── config
├── index.js
├── lib
└── screens
More Information about this, you find here:
https://medium.com/the-react-native-log/organizing-a-react-native-project-9514dfadaa0

How to build multiple APKs from a single source project

I wanna get multiple APKs from a single source project.
Just the application's title, icon, and package name are different with the others.
The project is on gradle(1.12), as below.
.
└── my_project
├── build.gradle
├── settings.gradle
└── module
├── build.gradle
└── src
How can I do that?
You can use productFlavors for that, and the under the promo and full folders (for example) create strings file (promo/res/values/strings.xml) with the update title value, same approach goes for the icon.
productFlavors {
promo {
packageName "com.woony.promo"
versionCode 1
versionName "v1.0.0_promo"
}
full {
packageName "com.woony"
versionCode 1
versionName "v1.0.0"
}
}
The updated project structure should be like the following
.
└── my_project
├── build.gradle
├── settings.gradle
└── module
├── build.gradle
└── src
├── main
├── promo
└── full
And to generate the release apks just call the following once (just make sure you added signingConfigs and linked it in your release buildTypes)
gradle assembleRelease
All the common files like java code, manifest and base resources are under "src/main"
Move your applications specific folders into "src/projects"
declare two productFlavor (one per applications) specifying applicationId and versionName
create two sourceSet (one per project) indicating the specific res, java, etc.. folders (i just needed res folder)
Full project's structure
Now, use Build Variants (bottom-left of Android Studio) to select the application to run

How to create the best Android app project structure with Android Studio and Gradle?

I'm trying to switch to Android Studio and Gradle, but I have quite some issues with both integration into Studio and build with Gradle.
I've got an app that relies on several libraries.
I'd like to use Android Studio, and Gradle build system.
I'm using git
Most of my libraries are directly git cloned from their github location
Currently, what I have is:
Main Project
├── GH Lib 1
│ ├── <some stuff from the lib>
│ └── library
│ ├── AndroidManifest.xml
│ ├── res
│ └── src
├── GH Lib 2
│ └── <same structure as the lib 1>
├── GH Lib 3
│ └── <same structure as the lib 1>
│── GH Lib 4
│ └── <same structure as the lib 1>
└── My App folder
└── AndroidManifest.xml
└── res
└── src
└── libs
Each of the 'GH Lib X' directory is the result of a git clone from GitHub (for example: ActionBarSherlock).
'My app folder' contains directly res, src, AndroidManifest.xml, libs (with jars), etc.
1st question
I would like to understand how I can integrate all of this in Studio, with Gradle. Currently each lib is a module, and contains a build.gradle file. My App contains also a build.gradle file, however I can't reference dependencies from other folders, because they are in the parent folder, and this AFAIK can't be done with Gradle.
Would this structure be better?
My App Folder
│── AndroidManifest.xml
│── res
│── src
│── libs
└── dependencies
│── GH Lib 1
│── GH Lib 2
│── GH Lib 3
│── GH Lib 4
└── My App folder
My second question related to this is integration with git. Currently all libs are git submodules, is it a good idea?
You should look at the multiproject example for the layout attached in the doc.
http://tools.android.com/tech-docs/new-build-system
http://docs.google.com/viewer?a=v&pid=sites&srcid=YW5kcm9pZC5jb218dG9vbHN8Z3g6NDYzNTVjMjNmM2YwMjhhNA
Essentially you want a top level settings.gradle that tie all the pieces together. Ideally they should be in one single git repo to make your life easier. However you probably can use symlink to tie them into a common build repo that contain your top level settings.gradle.
This structure will work just fine. I have a similar structure and everything OK in Ubuntu 13.04 and Android Studio 130.729444.
You should provide settings.gradle file in root project with references (basically it's a relative path) to each module which should be built.
include ':my-app', ':gh-lib-1:library', ':gh-lib-2:library'
Root build.gradle file should contain tasks/configuration which will be common for all projects. More about multi-project setup can be found here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
Right now your source directories location does not conform to the default Android Studio setup. You can either move your src, res directories or setup sourceSets configuration in your build.gradle. It should be done for each project. More about project structure: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
After these steps you may try to import your project to Android Studio by selecting root build.gradle file in the 'Import project' dialog.
It's possible that at first you will be unable to build the project in IDE due to Task 'assemble' not found in root project error. This is a bug in Android Studio. Fortunately, there is a workaround for this - just include task assemble{} in build.gradle files for all 'root' projects.

For Android project how do I get maven to pickup all libraries in lib directory including .so files?

I have project that compiles and links fine when using Eclipse IDE. This project uses some external jar files and also uses some of JNI ( .so ) libraries.
They are all located in the libs/ directory of my project. How should my pom.xml file look like in order for all the jar files in libs/ folder and the shared objects are included in the APK. My libs directory looks something like this:
libs/
├── mydevicelib.jar
├── armeabi
│   ├── libdevice.so
├── armeabi-v7a
│   ├── libdevice.so
│   ├── libcmiris.so
├── libcommon.jar
I am using maven 3.0.5
These jars should be included as dependencies in the maven POM.
Rather than include them in a local lib folder they should be deployed to a maven repository.
For any artifacts that are available through maven central repository just include the dependency directly from there.
For custom artifacts, the best way to do this is to set up your own maven repository (http://archiva.apache.org/index.cgi or http://www.sonatype.org/nexus/) and deploy the artifacts to that. Then you can include them as dependencies in the pom.
Alternatively, if this is overkill for your project, you can set up a local project repository and deploy the artifacts to that.
I havent actually done this with JNI libraries, though this link looks like it may contain useful info for doing a similar thing there: http://code.google.com/p/maven-android-plugin/wiki/NativeLibsAsDependencies. Looks like you just need to add the
<type>so</type>
element to the dependency.

Categories

Resources