How to use opencv in using Gradle? - android

I want to use Android Studio to develop an app using Gradle build tool. I can not insert the OpenCV repo and library on build.gradle. My .gradle file is like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
How can I add OpenCV in my project?

You can do this very easily in Android Studio.
Follow the below steps to add Open CV in your project as library.
Create a libraries folder underneath your project main directory. For example, if your project is OpenCVExamples, you would create a OpenCVExamples/libraries folder.
Go to the location where you have SDK "\OpenCV-2.4.8-android-sdk\sdk" here you will find the java folder, rename it to opencv.
Now copy the complete opencv directory from the SDK into the libraries folder you just created.
Now create a build.gradle file in the opencv directory with the following contents
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 2480
versionName "2.4.8"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
Edit your settings.gradle file in your application’s main directory and add this line:
include ':libraries:opencv'
Sync your project with Gradle and it should looks like this
Right click on your project then click on the Open Module Settings then Choose Modules from the left-hand list, click on your application’s module, click on the Dependencies tab, and click on the + button to add a new module dependency.
Choose Module dependency. It will open a dialog with a list of modules to choose from; select “:libraries:opencv”.
Create a jniLibs folder in the /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs from the OpenCV SDK.
Click OK. Now everything done, go and enjoy with OpenCV.

Since the integration of OpenCV is such an effort, we pre-packaged it and published it via JCenter here: https://github.com/quickbirdstudios/opencv-android
Just include this in your module's build.gradle dependencies section
dependencies {
implementation 'com.quickbirdstudios:opencv:3.4.1'
}
and this in your project's build.gradle repositories section
repositories {
jcenter()
}
You won't get lint error after gradle import but don't forget to initialize the OpenCV library like this in MainActivity
public class MainActivity extends Activity {
static {
if (!OpenCVLoader.initDebug())
Log.d("ERROR", "Unable to load OpenCV");
else
Log.d("SUCCESS", "OpenCV loaded");
}
...
...
...
...

As per OpenCV docs(1), below steps using OpenCV manager is the recommended way to use OpenCV for production runs. But, OpenCV manager(2) is an additional install from Google play store. So, if you prefer a self contained apk(not using OpenCV manager) or is currently in development/testing phase, I suggest answer at https://stackoverflow.com/a/27421494/1180117.
Recommended steps for using OpenCV in Android Studio with OpenCV manager.
Unzip OpenCV Android sdk downloaded from OpenCV.org(3)
From File -> Import Module, choose sdk/java folder in the unzipped opencv archive.
Update build.gradle under imported OpenCV module to update 4 fields to match your project's build.gradle a) compileSdkVersion b) buildToolsVersion c) minSdkVersion and 4) targetSdkVersion.
Add module dependency by Application -> Module Settings, and select the Dependencies tab. Click + icon at bottom(or right), choose Module Dependency and select the imported OpenCV module.
As the final step, in your Activity class, add snippet below.
public class SampleJava extends Activity {
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch(status) {
case LoaderCallbackInterface.SUCCESS:
Log.i(TAG,"OpenCV Manager Connected");
//from now onwards, you can use OpenCV API
Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
break;
case LoaderCallbackInterface.INIT_FAILED:
Log.i(TAG,"Init Failed");
break;
case LoaderCallbackInterface.INSTALL_CANCELED:
Log.i(TAG,"Install Cancelled");
break;
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
Log.i(TAG,"Incompatible Version");
break;
case LoaderCallbackInterface.MARKET_ERROR:
Log.i(TAG,"Market Error");
break;
default:
Log.i(TAG,"OpenCV Manager Install");
super.onManagerConnected(status);
break;
}
}
};
#Override
protected void onResume() {
super.onResume();
//initialize OpenCV manager
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
}
}
Note: You could only make OpenCV calls after you receive success callback on onManagerConnected method. During run, you will be prompted for installation of OpenCV manager from play store, if it is not already installed. During development, if you don't have access to play store or is on emualtor, use appropriate OpenCV manager apk present in apk folder under downloaded OpenCV sdk archive .
Pros
Apk size reduction by around 40 MB ( consider upgrades too ).
OpenCV manager installs optimized binaries for your hardware which could help speed.
Upgrades to OpenCV manager might save your app from bugs in OpenCV.
Different apps could share same OpenCV library.
Cons
End user experience - might not like a install prompt from with your
application.

If you don't want to use JavaCV this works for me...
Step 1- Download the Resources
Download OpenCV Android SDK from http://opencv.org/downloads.html
Step 2 - Copying the OpenCV binaries into your APK
Copy libopencv_info.so & libopencv_java.so from
OpenCV-2.?.?-android-sdk -> sdk -> native -> libs -> armeabi-v7a
to
Project Root -> Your Project -> lib - > armeabi-v7a
Zip the lib folder up and rename that zip to whatever-v7a.jar.
Copy this .jar file and place it in here in your project
Project Root -> Your Project -> libs
Add this line to your projects build.gradle in the dependencies section
compile files('libs/whatever-v7a.jar')
When you compile now you will probably see your .apk is about 4mb bigger.
(Repeat for "armeabi" if you want to support ARMv6 too, likely not needed anymore.)
Step 3 - Adding the java sdk to your project
Copy the java folder from here
OpenCV-2.?.?-android-sdk -> sdk
to
Project Root -> Your Project -> libs (Same place as your .jar file);
(You can rename the 'java' folder name to 'OpenCV')
In this freshly copied folder add a typical build.gradle file; I used this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral();
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In your Project Root settings.gradle file change it too look something like this:
include ':Project Name:libs:OpenCV', ':Project Name'
In your Project Root -> Project Name -> build.gradle file in the dependencies section add this line:
compile project(':Project Name:libs:OpenCV')
Step 4 - Using OpenCV in your project
Rebuild and you should be able to import and start using OpenCV in your project.
import org.opencv.android.OpenCVLoader;
...
if (!OpenCVLoader.initDebug()) {}
I know this if a bit of hack but I figured I would post it anyway.

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url 'http://maven2.javacv.googlecode.com/git/'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.googlecode.javacv:javacv:0.5'
instrumentTestCompile 'junit:junit:4.4'
}
android {
compileSdkVersion 14
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 14
}
}
This is worked for me :)

I have posted a new post about how to build an Android NDK application with OpenCV included
using Android Studio and Gradle. More information can be seen here, I have summarized two methods:
(1) run ndk-build within Gradle task
sourceSets.main.jni.srcDirs = []
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
commandLine "$ndkDir/ndk-build",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=src/main/jniLibs',
'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
(2) run ndk-build with an external tool
Parameters: NDK_PROJECT_PATH=$ModuleFileDir$/build/intermediates/ndk NDK_LIBS_OUT=$ModuleFileDir$/src/main/jniLibs NDK_APPLICATION_MK=$ModuleFileDir$/src/main/jni/Application.mk APP_BUILD_SCRIPT=$ModuleFileDir$/src/main/jni/Android.mk V=1
More information can be seen here

It works with Android Studio 1.2 + OpenCV-2.4.11-android-sdk (.zip), too.
Just do the following:
1) Follow the answer that starts with "You can do this very easily in Android Studio. Follow the steps below to add OpenCV in your project as library." by TGMCians.
2) Modify in the <yourAppDir>\libraries\opencv folder your newly created build.gradle to (step 4 in TGMCians' answer, adapted to OpenCV2.4.11-android-sdk and using gradle 1.1.0):
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 2411
versionName "2.4.11"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['src']
}
}
}
3) *.so files that are located in the directories "armeabi", "armeabi-v7a", "mips", "x86" can be found under (default OpenCV-location): ..\OpenCV-2.4.11-android-sdk\OpenCV-android-sdk\sdk\native\libs (step 9 in TGMCians' answer).
Enjoy and if this helped, please give a positive reputation. I need 50 to answer directly to answers (19 left) :)

The OpenCV Android SDK has an example gradle.build file with helpful comments: https://github.com/opencv/opencv/blob/master/modules/java/android_sdk/build.gradle.in
//
// Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
//
// This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
//
// Add module into Android Studio application project:
//
// - Android Studio way:
// (will copy almost all OpenCV Android SDK into your project, ~200Mb)
//
// Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
// Source directory: select this "sdk" directory
// Module name: ":opencv"
//
// - or attach library module from OpenCV Android SDK
// (without copying into application project directory, allow to share the same module between projects)
//
// Edit "settings.gradle" and add these lines:
//
// def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
// // You can put declaration above into gradle.properties file instead (including file in HOME directory),
// // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
// include ':opencv'
// project(':opencv').projectDir = new File(opencvsdk + '/sdk')
//
//
//
// Add dependency into application module:
//
// - Android Studio way:
// "Open Module Settings" (F4) -> "Dependencies" tab
//
// - or add "project(':opencv')" dependency into app/build.gradle:
//
// dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
// ...
// implementation project(':opencv')
// }
//
//
//
// Load OpenCV native library before using:
//
// - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
// It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
//
// - use "System.loadLibrary("opencv_java3")" or "OpenCVLoader.initDebug()"
// TODO: Add accurate API to load OpenCV native library
//
//
//
// Native C++ support (necessary to use OpenCV in native code of application only):
//
// - Use find_package() in app/CMakeLists.txt:
//
// find_package(OpenCV 3.4 REQUIRED java)
// ...
// target_link_libraries(native-lib ${OpenCV_LIBRARIES})
//
// - Add "OpenCV_DIR" and enable C++ exceptions/RTTI support via app/build.gradle
// Documentation about CMake options: https://developer.android.com/ndk/guides/cmake.html
//
// defaultConfig {
// ...
// externalNativeBuild {
// cmake {
// cppFlags "-std=c++11 -frtti -fexceptions"
// arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" // , "-DANDROID_ARM_NEON=TRUE"
// }
// }
// }
//
// - (optional) Limit/filter ABIs to build ('android' scope of 'app/build.gradle'):
// Useful information: https://developer.android.com/studio/build/gradle-tips.html (Configure separate APKs per ABI)
//
// splits {
// abi {
// enable true
// reset()
// include 'armeabi-v7a' // , 'x86', 'x86_64', 'arm64-v8a'
// universalApk false
// }
// }
//
apply plugin: 'com.android.library'
println "OpenCV: " + project.buildscript.sourceFile
android {
compileSdkVersion 27
//buildToolsVersion "27.0.3" // not needed since com.android.tools.build:gradle:3.0.0
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets {
main {
jniLibs.srcDirs = ['native/libs']
java.srcDirs = ['java/src']
aidl.srcDirs = ['java/src']
res.srcDirs = ['java/res']
manifest.srcFile 'java/AndroidManifest.xml'
}
}
}
dependencies {
}

These are the steps necessary to use OpenCV with Android Studio 1.2:
Download OpenCV and extract the archive
Open your app project in Android Studio
Go to File -> New -> Import Module...
Select sdk/java in the directory you extracted before
Set Module name to opencv
Press Next then Finish
Open build.gradle under imported OpenCV module and update compileSdkVersion and buildToolsVersion to versions you have on your machine
Add compile project(':opencv') to your app build.gradle
dependencies {
...
compile project(':opencv')
}
Press Sync Project with Gradle Files

I've imported the Java project from OpenCV SDK into an Android Studio gradle project and made it available at https://github.com/ctodobom/OpenCV-3.1.0-Android
You can include it on your project only adding two lines into build.gradle file thanks to jitpack.io service.

The following permissions and features are necessary in the AndroidManifest.xml file without which you will get the following dialog box
"It seems that your device does not support camera (or it is locked). Application will be closed"
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

OpenCV, Android Studio 1.4.1, gradle-experimental plugin 0.2.1
None of the other answers helped me. Here's what worked for me. I'm using the tutorial-1 sample from opencv but I will be doing using the NDK in my project so I'm using the gradle-experimental plugin which has a different structure than the gradle plugin.
Android studio should be installed, the Android NDK should be installed via the Android SDK Manager, and the OpenCV Android SDK should be downloaded and unzipped.
This is in chunks of bash script to keep it compact but complete. It's also all on the command line because on of the big problems I had was that in-IDE instructions were obsolete as the IDE evolved.
First set the location of the root directory of the OpenCV SDK.
export OPENCV_SDK=/home/user/wip/OpenCV-2.4.11-android-sdk
cd $OPENCV_SDK
Create your gradle build files...
First the OpenCV library
cat > $OPENCV_SDK/sdk/java/build.gradle <<'==='
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
minSdkVersion.apiLevel = 8
targetSdkVersion.apiLevel = 23
}
}
android.buildTypes {
release {
minifyEnabled = false
}
debug{
minifyEnabled = false
}
}
android.sources {
main.manifest.source.srcDirs += "."
main.res.source.srcDirs += "res"
main.aidl.source.srcDirs += "src"
main.java.source.srcDirs += "src"
}
}
===
Then tell the tutorial sample what to label the library as and where to find it.
cat > $OPENCV_SDK/samples/tutorial-1-camerapreview/settings.gradle <<'==='
include ':openCVLibrary2411'
project(':openCVLibrary2411').projectDir = new File('../../sdk/java')
===
Create the build file for the tutorial.
cat > $OPENCV_SDK/samples/tutorial-1-camerapreview/build.gradle <<'==='
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "org.opencv.samples.tutorial1"
minSdkVersion.apiLevel = 8
targetSdkVersion.apiLevel = 23
}
}
android.sources {
main.manifest.source.srcDirs += "."
main.res.source.srcDirs += "res"
main.aidl.source.srcDirs += "src"
main.java.source.srcDirs += "src"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
debug {
minifyEnabled = false
}
}
}
dependencies {
compile project(':openCVLibrary2411')
}
===
Your build tools version needs to be set correctly. Here's an easy way
to see what you have installed. (You can install other versions via the
Android SDK Manager). Change buildToolsVersion if you don't have 23.0.2.
echo "Your buildToolsVersion is one of: "
ls $ANDROID_HOME/build-tools
Change the environment variable on the first line to your version number
REP=23.0.2 #CHANGE ME
sed -i.bak s/23\.0\.2/${REP}/g $OPENCV_SDK/sdk/java/build.gradle
sed -i.bak s/23\.0\.2/${REP}/g $OPENCV_SDK/samples/tutorial-1-camerapreview/build.gradle
Finally, set up the correct gradle wrapper. Gradle needs a clean directory
to do this.
pushd $(mktemp -d)
gradle wrapper --gradle-version 2.5
mv -f gradle* $OPENCV_SDK/samples/tutorial-1-camerapreview
popd
You should now be all set. You can now browse to this directory with Android Studio and open up the project.
Build the tutoral on the command line with the following command:
./gradlew assembleDebug
It should build your apk, putting it in ./build/outputs/apk

Related

How can I open an older project(with an SDK version of 23) in android

I am following the book Practical Android by Mark Wickham. I am trying to open the source code from the Connections app here, but am running into many problems as it's an older project(2018).
Problems
Stuck on the loading screen devices; cannot run project
What I've tried
Invalidating cache/restarting from this link Android Studio device list stuck on loading
https://medium.com/updating-old-android-studio-projects-to-work-in/updating-old-android-studio-projects-to-work-in-android-studio-3-0-195eec3a9b33 Following this link, but I cannot find any gradle-wrapper in my project.
In this app specifically, my screen looks like this:
If you look at the very top, I am unable to choose any device. Please note this does not happen with any other project(tried creating blank project, problem didn't occur).
How can I run this project?
Thanks!
App build.grade:
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.wickham.android.connections"
minSdkVersion 19
targetSdkVersion 30
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def project = "Connections"
def SEP = "_"
def buildType = variant.variantData.variantConfiguration.buildType.name
def version = variant.versionName
def date = new Date();
def formattedDate = date.format('ddMMyy_HHmm')
def newApkName = project + SEP + version + SEP + formattedDate + ".apk"
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
}
Project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
I have just minorly edited the build.gradle from the connections app here: https://github.com/Apress/practical-android
The most probably is that the version of the gradle build tools of these projects is not compatible with the build tools that your Android Studio supports..
So before opening any of these projects (to keep them unmodified by Android Studio), you can migrate them to the gradle version that already you've on android-studio. To do that you can use a text editor to change:
In myAppName\gradle\wrapper\gradle-wrapper.properties file, in the line distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip: change to the gradle version you've (so you need to change this number in your example 6.7.1)
You can know the current gradle version(s) of Android studio from C:/Users/myUserName/.gradle/wrapper/dists/
In myAppName\build.gradle you need to change the gradle plugin version to be matched with the gradle distribution version you've from step no.1. Documentation table that lists which version of Gradle is required for each version of the Android Gradle plugin.
UPDATE
Please follow below procedure.. it is tedious but works:
Create a brand new project that has a package name that is the same as that of your project.
Copy src, lib, raw .. or any assets folders under /app of your project into the /app of the brand new project ..
Remove the themes.xml files
Copy dependency from \app\build.gradle to the new project & replace compile with implementation, and testCompile with testImplementation
I did a test on one of the apps emailing app and it runs.

Error with building Google VR SDK sample code

I'm a newbie for developing android program and I'm struggling to get the sample code "ndk-treasurehunt" running. I followed the instructions to build the project and ran into many errors. After modified the build.gradle file, I was able to make a few progress but right now I'm still stuck with the following error.
Build command failed.
Error while executing process C:\Users\xxx\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\xxx\ProgrammingAndroid\gvr-android-sdk-1.150.0\samples\ndk-treasurehunt.externalNativeBuild\cmake\debug\x86 --target treasurehunt_jni}
ninja: error: '../../../../libraries/jni/x86/libgvr.so', needed by '../../../../build/intermediates/cmake/debug/obj/x86/libtreasurehunt_jni.so', missing and no known rule to make it.
The build.gradle I modified is like this:
apply plugin: 'com.android.application'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.google.vr.ndk.samples.controllerpaint"
minSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
cppFlags "-std=gnu++11"
arguments "-DGVR_LIBPATH=${project.rootDir}/libraries/jni",
"-DGVR_INCLUDE=${project.rootDir}/libraries/headers"
}
}
buildTypes {
release {
minifyEnabled = true
proguardFiles.add(file("${project.rootDir}/proguard-gvr.txt"))
}
}
ndk {
// This sample builds all architectures by default. Note that if you
// only want to build for a specific architecture, you need to
// remove the appropriate lines below. You also need to remove the
// .so files from the apk using
// "packagingOptions {exclude('lib/armeabi-v7a/*')}" in the android
// section.
abiFilters "arm64-v8a"
abiFilters "armeabi-v7a"
abiFilters "x86"
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation 'com.google.vr:sdk-audio:1.150.0'
implementation 'com.google.vr:sdk-base:1.150.0'
}
build.dependsOn(':extractNdk')
Please help! Thank you!
Please ensure that your NDK is installed and extracted correctly by performing the following:
Add the NDK to Android Studio via: Tools -> SDK Manager -> SDK Tools -> NDK
Open Android Studio Terminal at the bottom of IDE or through View -> Tool Windows -> Terminal
Run the following command in the terminal gradelw :extractNdk
In the settings.gradle, uncomment the following line include ':sample:ndk-treasurehunt' which has since been replaced by include ':samples:ndk-hellovr' if you are using a newer NDK

How to add a shared library to my APK with Android Studio? [duplicate]

I read many threads how to add a *.so library to Android Studio, but none of them works, especially when it comes to the point of text: This does not work with the newer xxx (Android Studio, gradle, ...)
Can we make a fresh start please. I got:
Android Studio 0.6.0
From Project Structure I see:
SDK Location:
/usr/share/android-studio/data/sdk
/usr/lib/jvm/default-java
Project:
Gradle version 1.10
Android Plugin Version 0.11.+
Modules/app:
Properties:
Compile Sdk Version 19
Build Tools Version 19.1.0
Dependencies:
{dir=libs, include=[*.jar]} Compile
{dir=libs, include=[*.so]} Provided
m com.android.support: appcompat -v7:19.+ Compile
I got the *.so files pre-compiled and at the demo app they are working. I have to change the source code of the app, so I need to rebuild with the same *.so files.
Adding .so Library in Android Studio 1.0.2
Create Folder "jniLibs" inside "src/main/"
Put all your .so libraries inside "src/main/jniLibs" folder
Folder structure looks like,
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
|--|--|--|--|--x86
|--|--|--|--|--|--.so Files
No extra code requires just sync your project and run your application.
Reference
https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main
Current Solution
Create the folder project/app/src/main/jniLibs, and then put your *.so files within their abi folders in that location. E.g.,
project/
├──libs/
| └── *.jar <-- if your library has jar files, they go here
├──src/
└── main/
├── AndroidManifest.xml
├── java/
└── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── yourlib.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── yourlib.so
└── x86/ <-- Intel 32bit
└── yourlib.so
Deprecated solution
Add both code snippets in your module gradle.build file as a dependency:
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
How to create this custom jar:
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
Same answer can also be found in related question: Include .so library in apk in android studio
Solution 1 : Creation of a JniLibs folder
Create a folder called “jniLibs” into your app and the folders containing your *.so inside.
The "jniLibs" folder needs to be created in the same folder as your "Java" or "Assets" folders.
Solution 2 : Modification of the build.gradle file
If you don’t want to create a new folder and keep your *.so files into the libs folder, it is possible !
In that case, just add your *.so files into the libs folder (please respect the same architecture as the solution 1 : libs/armeabi/.so for instance) and modify the build.gradle file of your app to add the source directory of the jniLibs.
sourceSets {
main {
jniLibs.srcDirs = ["libs"]
}
}
You will have more explanations, with screenshots to help you here ( Step 6 ):
http://blog.guillaumeagis.eu/setup-andengine-with-android-studio/
EDIT It had to be jniLibs.srcDirs, not jni.srcDirs - edited the code. The directory can be a [relative] path that points outside of the project directory.
*.so library in Android Studio
You have to generate jniLibs folder inside main in android Studio projects and put your all .so files inside. You can also integrate this line in build.gradle
compile fileTree(dir: 'libs', include: ['.jar','.so'])
It's work perfectly
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
This is the project structure.
This is my build.gradle file, Please note the line
jniLibs.srcDirs = ['libs']
This will include libs's *.so file to apk.
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
Android NDK official hello-libs CMake example
https://github.com/googlesamples/android-ndk/tree/840858984e1bb8a7fab37c1b7c571efbe7d6eb75/hello-libs
Just worked for me on Ubuntu 17.10 host, Android Studio 3, Android SDK 26, so I strongly recommend that you base your project on it.
The shared library is called libgperf, the key code parts are:
hello-libs/app/src/main/cpp/CMakeLists.txt:
// -L
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
// -I
target_include_directories(hello-libs PRIVATE
${distribution_DIR}/gperf/include)
// -lgperf
target_link_libraries(hello-libs
lib_gperf)
app/build.gradle:
android {
sourceSets {
main {
// let gradle pack the shared library into apk
jniLibs.srcDirs = ['../distribution/gperf/lib']
Then, if you look under /data/app on the device, libgperf.so will be there as well.
on C++ code, use: #include <gperf.h>
header location: hello-libs/distribution/gperf/include/gperf.h
lib location: distribution/gperf/lib/arm64-v8a/libgperf.so
If you only support some architectures, see: Gradle Build NDK target only ARM
The example git tracks the prebuilt shared libraries, but it also contains the build system to actually build them as well: https://github.com/googlesamples/android-ndk/tree/840858984e1bb8a7fab37c1b7c571efbe7d6eb75/hello-libs/gen-libs
I have solved a similar problem using external native lib dependencies that are packaged inside of jar files. Sometimes these architecture dependend libraries are packaged alltogether inside one jar, sometimes they are split up into several jar files. so i wrote some buildscript to scan the jar dependencies for native libs and sort them into the correct android lib folders. Additionally this also provides a way to download dependencies that not found in maven repos which is currently usefull to get JNA working on android because not all native jars are published in public maven repos.
android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "myappid"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ["src/main/jniLibs", "$buildDir/native-libs"]
}
}
}
def urlFile = { url, name ->
File file = new File("$buildDir/download/${name}.jar")
file.parentFile.mkdirs()
if (!file.exists()) {
new URL(url).withInputStream { downloadStream ->
file.withOutputStream { fileOut ->
fileOut << downloadStream
}
}
}
files(file.absolutePath)
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'net.java.dev.jna:jna:4.2.0'
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-arm.jar?raw=true', 'jna-android-arm')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-armv7.jar?raw=true', 'jna-android-armv7')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-aarch64.jar?raw=true', 'jna-android-aarch64')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-x86.jar?raw=true', 'jna-android-x86')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-x86-64.jar?raw=true', 'jna-android-x86_64')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-mips.jar?raw=true', 'jna-android-mips')
compile urlFile('https://github.com/java-native-access/jna/blob/4.2.2/lib/native/android-mips64.jar?raw=true', 'jna-android-mips64')
}
def safeCopy = { src, dst ->
File fdst = new File(dst)
fdst.parentFile.mkdirs()
fdst.bytes = new File(src).bytes
}
def archFromName = { name ->
switch (name) {
case ~/.*android-(x86-64|x86_64|amd64).*/:
return "x86_64"
case ~/.*android-(i386|i686|x86).*/:
return "x86"
case ~/.*android-(arm64|aarch64).*/:
return "arm64-v8a"
case ~/.*android-(armhf|armv7|arm-v7|armeabi-v7).*/:
return "armeabi-v7a"
case ~/.*android-(arm).*/:
return "armeabi"
case ~/.*android-(mips).*/:
return "mips"
case ~/.*android-(mips64).*/:
return "mips64"
default:
return null
}
}
task extractNatives << {
project.configurations.compile.each { dep ->
println "Scanning ${dep.name} for native libs"
if (!dep.name.endsWith(".jar"))
return
zipTree(dep).visit { zDetail ->
if (!zDetail.name.endsWith(".so"))
return
print "\tFound ${zDetail.name}"
String arch = archFromName(zDetail.toString())
if(arch != null){
println " -> $arch"
safeCopy(zDetail.file.absolutePath,
"$buildDir/native-libs/$arch/${zDetail.file.name}")
} else {
println " -> No valid arch"
}
}
}
}
preBuild.dependsOn(['extractNatives'])
I have android studio 4.1.2 and when I tried to set the ndk path in File -> Project Structure -> Sdk Location it would ask me to download the ndk even though it was already installed, I set the NDK_HOME, ANDROID_NDK_HOME and PATH environmental variables and nothing. The only thing that worked for me was manually setting the ndk version in the local.properties, creating a jniLibs (yes with this exact name) folder with the ABIs and their respective .so files and specifying the abi filters and ndk version in the build.gradle. Hope this saves someone else from a headache.
local.properties
ndk.dir=C\:\\Users\\<user>\\AppData\\Local\\Android\\Sdk\\ndk\\22.0.7026061
build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
jniLibs.srcDir 'jniLibs'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
ndkVersion '22.0.7026061'
}
...\app\src\main\
Inside the jniLibs folder
To use native-library (so files)
You need to add some codes in the "build.gradle" file.
This code is for cleaing "armeabi" directory and copying 'so' files into "armeabi" while 'clean project'.
task copyJniLibs(type: Copy) {
from 'libs/armeabi'
into 'src/main/jniLibs/armeabi'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(copyJniLibs)
}
clean.dependsOn 'cleanCopyJniLibs'
I've been referred from the below.
https://gist.github.com/pocmo/6461138

SIPdroid Android Studio ndk integration error

I'm currently using Android Studio 2.0 preview 4. I have followed the guide from tools.android.com and tested NDK samples from github. The samples worked without a hitch, but when I implemented it on the SIPdroid project, it throws this error when I rebuild the project:
Error:(78, 1) A problem occurred configuring project ':app'.
Exception thrown while executing model rule: model.android
Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl
when I try to use gradle project sync it gives this error:
Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Possible causes for this unexpected error include:You are using JDK version 'java version "1.7.0_79"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
Open JDK SettingsGradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Android project structure now looks like this. previously the jni folder is separated from the java folder.
Here's my config:
SIPdroid/app/build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.test.sipdroid"
minSdkVersion = 15
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
/*
* native build settings
*/
android.ndk {
moduleName = "SIPdroid"
/*
* Other ndk flags configurable here are
* cppFlags.add("-fno-rtti")
* cppFlags.add("-fno-exceptions")
* ldLibs.addAll(["android", "log"])
* stl = "system"
*/
}
android.sources {
main.java {
source {
srcDir 'src'
}
}
main.jni {
source {
srcDirs = []
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
SIPdroid/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
// classpath 'com.android.tools.build:gradle:1.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
SIPdroid/gradle-wrapper.properties
#Mon Jan 04 16:06:26 PHT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
SIPdroid/local.properties
ndk.dir=/path/Android/sdk/ndk-bundle
sdk.dir=/path/Android/sdk
I just recently solved my issue by adding this to my orignal app/build.gradle file without using the experimental gradle build ('com.android.tools.build:gradle-experimental:0.4.0') as indicated in the google samples.
This solution finally solved the issue NDKBuild Failure. This additional script builds your jni files using ndkBuild.
app/build.gradle
sourceSets.main {
jniLibs.srcDir 'src/main/libs' // use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec) {
// commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath <-- Not working
commandLine '/home/user/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
SIPdroid/build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
You also need to have an empty libs folder under app/src/main. My mistake was that I renamed the /jni folder to /libs. After running the build, it will compile your jni to the /libs folder to .so files
jniLibs in your Android project structure view will look like this. This is from your app/src/main/libs as indicated in your build.gradle script
I hope this helps.

aidl is missing android studio

Environment:
Mac OS 10.10.3
Android studio:1.2.11
grandle:2.2.1
the log:
Information:Gradle tasks [:generateDebugSources, :generateDebugTestSources]
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl FAILED
Error:Execution failed for task ':compileDebugAidl'.
> aidl is missing
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
String SDK_DIR = System.getenv("ANDROID_HOME")
if(SDK_DIR == null) {
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file("local.properties")))
SDK_DIR = props.get('sdk.dir');
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
proguardFiles 'proguard.cfg'
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
provided files("${SDK_DIR}/platforms/android-17/data/layoutlib.jar")
//compile files('libs/pass-v1.1.3.jar')
// compile files('libs/sdk-v1.0.0.jar')
}
before this, I had compile the android resource 4.4 on my Mac, and modified some files in OS system, I think it is the reason is that, but I've forget which file, Someone encountered this problem yet
In my case I downloaded version 22 of Android M and Android 5.1.1 using Android Studio 1.2.1.1 but when I try to do a Hello World this same error showed me
So the solution was go to do right click in app like the image below and choose "Open Module Settings".....
then there you have 2 options. I've changed both with the last version I had.
Compile SDK version to API 21 Lollipop
and Build Tools Version to 21.1.2
Finally clean the project and Build
UPDATE
Here is my build.gradle to compare with your build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.android.bmi"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
UPDATED
TO Get Android Studio 1.3 follow this steps
Open the Settings window by choosing File > Settings.
Choose the Appearance & Behavior > System Settings > Updates panel.
On the Updates panel, choose the option Automatically check updates for: Canary Chanel.
On the Updates panel, select Check Now to check for the latest canary build. 5. Download and install the build when you are prompted.
Then you'll have something like this to update your Android Studio to 1.3 and with this you can test Android M
I solve my issue, set the build tools version from 21.1.2 to 22.0.1, hope it can help who meet the same.
For those you are still getting the "aidl is missing" error:
To me, setting back the build tools version is not a solution at all.
On your top level build.gradle file, try setting:
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.3.1'
and then use buildToolsVersion '23.0.1'.
It worked perfectly for me. I hope it helps others.
Following the screen shots from Jorge's post all you have to do is make sure you do not select Build Tools Version 23.0.0 rc1. I have not fully investigated that version in the IDE or on Google's bug tracker but all I had to do was pick the previous tool version and it worked just fine after doing a clean build. I tried this out with various SDK min versions.
I am running OSX 10.10.3 with Android Studio 1.2.1.1 running on Oracle JDK 1.8.0_45-b14
UPDATED WITH SOLUTION
This issue is identical in nature to Execution failed for task ':app:compileDebugAidl': aidl is missing. Please read my post for the proper solution and references to the genesis of the solution.
people who are building apps with android studio 1.3 preview might get Debug AIDL missing error
Solution:(Follow in sequence)
1) Download all the tools under preview channel (i.e. revision no 23.0.0 rc1)
2) Download play servies and android support repo support under extras
3)Restart Android Studio
4)Press F4 and set compile SDK version to API 22+ and Build tool version 23.0.0 rc1
5)open build.gradle(Project:******) and change classpath line with classpath 'com.android.tools.build:gradle:1.3.+'
I followed screenshots from Jorge's post. But did not have API 21 as an option. So I kept Compiled SDK Version 'API 22: Android 5.1 (Lollipop)' as it is and changed Build Tool Version from 23.0.0 rc1 to 22.0.1
I also had to install JDK 7 since 22.0.1 did not support JDK 6. After that gradle build succeded.
In my experience, there is not about Compile Sdk Version or Build Tool Version, is about the New Project Structure. According to this issue, Aidl files are supposed to be in src/main/aidl, once you put *.aidl at the supposed directory, Android Studio would serve it as expect.
And If you want to have them in src/main/java, then you need the remapping instruction as you've specified, like below :
sourceSets {
main {
aidl.srcDirs = ['src/main/java']
}
}
btw, in my situation, the remapping approach work only by Gradle 2.4(also probably above version).

Categories

Resources