How to create apk file for specific cpu architecture - android

I already know about split option available on gradle, which generates multiple apk for different cpu architectures.
How can I generate an apk included just armeabi-v7a and x86 architecture?

Step 1: Add the class path dependency to the project level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:3.7.1"
}
}
Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.
apply plugin: 'realm-android'
Step3: Add this to the application’s build.gradle:
realm {
syncEnabled = true;
}
Step4:Add this to the application’s build.gradle:
android{
defaultConfig{
applicatioId "com.android.abi.myapplication"
minSdkVersion 16
targetSdkVersion 25
ndk{
abiFilters "armeabi-v7a", "x86" // Add only required cpu architectures here
}
}
}
and Then sync the gradle and build the apk , will find only library files for armeabi-v7a and x86.

Related

No python interpreter configured for the model

I'm trying to run some python code in my app. (in android studio). But, I keep getting this error: "No python interpreter configured for the model" and thus I can't run even the simplest code like: print("hello").
Some details:
In my main package I opened a new python package, so I automatically have init.py file and I tried to run there: print("hello"), and also tried to open another python file in the same directory and put my code there but it won't run.
gurdle.build-s are provided.
p.s: I searched the internet for this problem, but no one talks about android studio, and everyone talks about choosing another SDK. However I don't have python SDK in my 'project structure', and when I tried to search one for download, I couldn't find any in 'SDK manager'.
details:
___________________________________________________
apply plugin: 'com.android.application'
apply plugin: "com.chaquo.python"
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.eyal.doctorsapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "x86", "armeabi-v7a"
}
python {
version "2.7.10"
}
}
___________________________________________________________________
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven{url "https://chaquo.com/maven"}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "com.chaquo.python:gradle:0.5.0"
}
}

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

run common gradle code in android base project gradle file

i have a library which uses all of our apps.
except for shared code and resources i wanted to share gradle code.
each app is constructed:
some_app/
|
- settings.gradle
- build.gradle
|
- mylib/
|
-build.gradle
- other_lib/
- app/
|
- build.gradle
right now i'm talking about the build.gradle in the root dir. The one that defines buildScript closure with dependecies and allprojects{} closure as well.
i tried to use apply from: './mylib/gradle_files/baseProject.gradle'
it works, but then my app can't find the android plugin. for some reason the classpath dependencies were not injected into the build script!
i then tried to create a list and use that:
ext.projectBaseDependencies = ['com.android.tools.build:gradle:2.1.2', 'com.google.gms:google-services:3.0.0']
I then used the list in my closure:
apply from: './mylib/gradle_files/baseProject.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath projectBaseDependencies
}
}
it doesn't work, gradle does not find my variable defined in baseProject.gradle.
I have a hunch that apply from works AFTER buildScript closure is evaluated :-(
Is there any way to share gradle script code across ALL apps ? if not apply from, what CAN work ? skip configuration and config in afterEvaluate {} clause ?
Why not use a Gradle file in your common library? If your common library includes a build.gradle file, you can apply the android library plugin:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
consumerProguardFiles "proguard-rules.pro"
}
}
dependencies {
// Your common dependencies here
}
Then you can include the library in your project's settings.gradle:
include ':mobile'
project(':common').projectDir = new File("/Users/example/path/to/common")
Then add it to your dependencies in the project's build.gradle:
dependencies {
compile project(':common')
// Your other project dependencies
}

How can I create aar file in android studio 1.3.1 while I've made the project without activity [duplicate]

I'd like to create an aar file for my library in Android Studio, i would've gone with a jar option but my library has resources.
Any idea how to create an aar file from a library?
If your library is set up as an Android library (i.e. it uses the apply plugin: 'com.android.library' statement in its build.gradle file), it will output an .aar when it's built. It will show up in the build/outputs/aar/ directory in your module's directory.
You can choose the "Android Library" type in File > New Module to create a new Android Library.
If you are still not seeing your aar file, select Build > Rebuild Project.
Retrieve exported .aar file from local builds
If you have a module defined as an android library project you'll get .aar files for all build flavors (debug and release by default) in the build/outputs/aar/ directory of that project.
your-library-project
|- build
|- outputs
|- aar
|- appframework-debug.aar
- appframework-release.aar
If these files don't exist start a build with
gradlew assemble
for macOS users
./gradlew assemble
Library project details
A library project has a build.gradle file containing apply plugin: com.android.library. For reference of this library packaged as an .aar file you'll have to define some properties like package and version.
Example build.gradle file for library (this example includes obfuscation in release):
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "0.1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Reference .aar file in your project
In your app project you can drop this .aar file in the libs folder and update the build.gradle file to reference this library using the below example:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 20
versionCode 4
versionName "0.4.0"
applicationId "yourdomain.yourpackage"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
dependencies {
compile 'be.hcpl.android.appframework:appframework:0.1.0#aar'
}
Alternative options for referencing local dependency files in gradle can be found at: http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project
Sharing dependencies using maven
If you need to share these .aar files within your organization check out maven. A nice write up on this topic can be found at: https://web.archive.org/web/20141002122437/http://blog.glassdiary.com/post/67134169807/how-to-share-android-archive-library-aar-across
About the .aar file format
An aar file is just a .zip with an alternative extension and specific content. For details check this link about the aar format.
just like user hcpl said but if you want to not worry about the version of the library you can do this:
dependencies {
compile(name:'mylibrary', ext:'aar')
}
as its kind of annoying to have to update the version everytime. Also it makes the not worrying about the name space easier this way.
To create AAR
while creating follow below steps.
File->New->New Module->Android Library and create.
To generate AAR
Go to gradle at top right pane in android studio follow below steps.
Gradle->Drop down library name -> tasks-> build-> assemble or assemble release
AAR will be generated in build/outputs/aar/
But if we want AAR to get generated in specific folder in project directory with name you want, modify your app level build.gradle like below
defaultConfig {
minSdkVersion 26
targetSdkVersion 28
versionCode System.getenv("BUILD_NUMBER") as Integer ?: 1
versionName "0.0.${versionCode}"
libraryVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "/../../../../release/" + ("your_recommended_name.aar")
}
}
}
Now it will create folder with name "release" in project directory which will be having AAR.
Updated Answer
In Latest releases specific path is not supported.Please add below code in library's build.gradle and rebuild project.After Rebuilding "aar",change project structure from Android to Project->navigate to your library->build->outputs->aar
android {
defaultConfig {
minSdkVersion ..
targetSdkVersion ..
versionCode ...
versionName "1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
libraryVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "${archivesBaseName}_${variant.name}_${defaultConfig.versionName}.aar"
}
}}
To import "aar" into project,check below link.
How to manually include external aar package using Gradle for Android
After following the first and second steps mentioned in the hcpl's answer in the same thread, we added , '*.aar'], dir: 'libs' in the our-android-app-project-based-on-gradle/app/build.gradle file as shown below:
...
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
...
Our gradle version is com.android.tools.build:gradle:3.2.1
btw #aar doesn't have transitive dependency. you need a parameter to turn it on:
Transitive dependencies not resolved for aar library using gradle
Finally got the solution here - https://stackoverflow.com/a/49663101/9640177
implementation files('libs/aar-file.aar')
Edit
I had one more complication - I had set minifyEnabled true for the library module.
[JAR vs AAR]
.jar is generated by apply plugin: 'java-library'
.aar is generated by apply plugin: 'com.android.library'
File -> New -> New Module... -> Android Library
If you have correctly set up for publishing, then you can just run this command to generate aar files.
./gradlew publishReleasePublicationToMavenLocal
This will generate a aar file inside <module-dir>/build/output/aar directory.
Now you can use this library in other local projects also. Add this in the project gradle in which you want to use this aar module
implementation fileTree(dir: '<location-to-library>/build/outputs/aar/', include: ['*.aar', '*.jar'], exclude: [])
Build ---> Build bundle/apk
.aar file will be generated in build/outputs/aar folder.

How to share SDK without src folder [duplicate]

I'd like to create an aar file for my library in Android Studio, i would've gone with a jar option but my library has resources.
Any idea how to create an aar file from a library?
If your library is set up as an Android library (i.e. it uses the apply plugin: 'com.android.library' statement in its build.gradle file), it will output an .aar when it's built. It will show up in the build/outputs/aar/ directory in your module's directory.
You can choose the "Android Library" type in File > New Module to create a new Android Library.
If you are still not seeing your aar file, select Build > Rebuild Project.
Retrieve exported .aar file from local builds
If you have a module defined as an android library project you'll get .aar files for all build flavors (debug and release by default) in the build/outputs/aar/ directory of that project.
your-library-project
|- build
|- outputs
|- aar
|- appframework-debug.aar
- appframework-release.aar
If these files don't exist start a build with
gradlew assemble
for macOS users
./gradlew assemble
Library project details
A library project has a build.gradle file containing apply plugin: com.android.library. For reference of this library packaged as an .aar file you'll have to define some properties like package and version.
Example build.gradle file for library (this example includes obfuscation in release):
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "0.1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Reference .aar file in your project
In your app project you can drop this .aar file in the libs folder and update the build.gradle file to reference this library using the below example:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 20
versionCode 4
versionName "0.4.0"
applicationId "yourdomain.yourpackage"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
dependencies {
compile 'be.hcpl.android.appframework:appframework:0.1.0#aar'
}
Alternative options for referencing local dependency files in gradle can be found at: http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project
Sharing dependencies using maven
If you need to share these .aar files within your organization check out maven. A nice write up on this topic can be found at: https://web.archive.org/web/20141002122437/http://blog.glassdiary.com/post/67134169807/how-to-share-android-archive-library-aar-across
About the .aar file format
An aar file is just a .zip with an alternative extension and specific content. For details check this link about the aar format.
just like user hcpl said but if you want to not worry about the version of the library you can do this:
dependencies {
compile(name:'mylibrary', ext:'aar')
}
as its kind of annoying to have to update the version everytime. Also it makes the not worrying about the name space easier this way.
To create AAR
while creating follow below steps.
File->New->New Module->Android Library and create.
To generate AAR
Go to gradle at top right pane in android studio follow below steps.
Gradle->Drop down library name -> tasks-> build-> assemble or assemble release
AAR will be generated in build/outputs/aar/
But if we want AAR to get generated in specific folder in project directory with name you want, modify your app level build.gradle like below
defaultConfig {
minSdkVersion 26
targetSdkVersion 28
versionCode System.getenv("BUILD_NUMBER") as Integer ?: 1
versionName "0.0.${versionCode}"
libraryVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "/../../../../release/" + ("your_recommended_name.aar")
}
}
}
Now it will create folder with name "release" in project directory which will be having AAR.
Updated Answer
In Latest releases specific path is not supported.Please add below code in library's build.gradle and rebuild project.After Rebuilding "aar",change project structure from Android to Project->navigate to your library->build->outputs->aar
android {
defaultConfig {
minSdkVersion ..
targetSdkVersion ..
versionCode ...
versionName "1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
libraryVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "${archivesBaseName}_${variant.name}_${defaultConfig.versionName}.aar"
}
}}
To import "aar" into project,check below link.
How to manually include external aar package using Gradle for Android
After following the first and second steps mentioned in the hcpl's answer in the same thread, we added , '*.aar'], dir: 'libs' in the our-android-app-project-based-on-gradle/app/build.gradle file as shown below:
...
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
...
Our gradle version is com.android.tools.build:gradle:3.2.1
btw #aar doesn't have transitive dependency. you need a parameter to turn it on:
Transitive dependencies not resolved for aar library using gradle
Finally got the solution here - https://stackoverflow.com/a/49663101/9640177
implementation files('libs/aar-file.aar')
Edit
I had one more complication - I had set minifyEnabled true for the library module.
[JAR vs AAR]
.jar is generated by apply plugin: 'java-library'
.aar is generated by apply plugin: 'com.android.library'
File -> New -> New Module... -> Android Library
If you have correctly set up for publishing, then you can just run this command to generate aar files.
./gradlew publishReleasePublicationToMavenLocal
This will generate a aar file inside <module-dir>/build/output/aar directory.
Now you can use this library in other local projects also. Add this in the project gradle in which you want to use this aar module
implementation fileTree(dir: '<location-to-library>/build/outputs/aar/', include: ['*.aar', '*.jar'], exclude: [])
Build ---> Build bundle/apk
.aar file will be generated in build/outputs/aar folder.

Categories

Resources