Slow build gradle in android - build

I checked all of the questions with answers about slow gradle build . (For Example here , here and ...) .but build gradle in my project is too slow . sometimes which building takes about 5-8 minuets , i searched in many sites , and now im tired
Build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "..."
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
additionalParameters('jack.incremental': 'true')
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
compileOptions {
incremental true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/TelegramNewApiLibrary.jar')
compile files('libs/TelegramNewConvert.jar')
}
repositories {
mavenCentral()
}
build.gradle(Module app):
// 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:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle.properties :
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon = true
my Anti-Virus is disabled and work offline is enable in project.
System Ram : 4G
System CPU : 3.10 GH
Android Studio Version : 2.2.3
any one can help me ?

Try to update AndroidStudio to 3.0, upgrade gradle gradle:2.2.3 => gradle:3.0.0 and buildtools buildToolsVersion '25.0.2' => buildToolsVersion '26.0.2'

Understand that Gradle Build has nothing to do with your CPU Speed or RAM. The reason why the Build gets slower in your PC is due to your Internet Connection. The build can take nearly ~100 MB approx. of data to complete it's process. Even if your Internet Connection is fast and your connection's PING speed is slow, it takes more time. Thanks for your time.

Related

How to change CMake path in Android Studio

I copied an existing Android Studio project from another user and I can't compile C++ files using CMake because it uses the other user's CMake path
I already tried to delete and re-create the CMakeLists.txt file and re-installed CMake using SDK Manager
Here's my gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
defaultConfig {
. . .
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
}
}
}
buildTypes {
release {
. . .
}
}
lintOptions {
abortOnError false
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
}
}
}
About 2 months ago, the project worked perfectly. Then I made some minor modifications and now I have this error.
It's just like there's a way to indicate which CMake use, but I don't know where to find it.
Here's a resume of what the console show me when I want to clean the project:
Caused by: net.rubygrapefruit.platform.NativeException: Could not start '/Users/Old_User/Library/Android/sdk/cmake/3.6.4111459/bin/cmake'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
The rest of the error log is about the same message saying that it can find the cmake file
It appears that android build system is not able to find cmake utility. Please check if it is installed.

How to fix Android NDK app crash with UnsatisfiedLinkError when loading protobuf-lite.so on Android 6.0?

I have created an Android application with a custom C++ library that depends on Google's protobuf-lite library. It works fine on all the recent devices I have tried to run it on (under Android 7, 8 and 8.1). However, I found that on older devices running Android 6.0.1 or 6.0 (Asus Nexus 7 and some old Motorola phone), the application crashes on loading the libprotobuf-lite.so dependency.
Here is the stacktrace I get:
E/AndroidRuntime: FATAL EXCEPTION:
main Process: com.mycompany.core, PID: 11582 java.lang.UnsatisfiedLinkError:
dlopen failed: cannot locate symbol "__aeabi_memmove8" referenced by "/data/app/com.mycompany.core-2/lib/arm/libprotobuf-lite.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.mycompany.core.CameraTestActivity.<clinit>(CameraTestActivity.java:46)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)$
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
This is really weird because the missing symbol "__aeabi_memmove8" appears to be a low-level standard library feature and I do not really grasp why it would not be found on Android 6.
In addition, I am quite confident that the issue comes from protobuf-lite not linking correctly because previous versions of my app, which were not using protobuf, ran fine on these Android 6 devices.
Below are some details on my config.
Protobuf version: 3.6.1
Lib package cross-compiled from source using Cmake GUI, NDK r18 toolchain and MinGW
Devices' ABI: armeabi-v7a
Android SDK compile version: API 28
Application build toolchain : Gradle + CMake.
Android Studio 3.1.3
Here is my build.gradle file:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mycompany.core"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk{
abiFilters "arm64-v8a", "armeabi-v7a"
}
}
debug {
ndk{
abiFilters "arm64-v8a", "armeabi-v7a"
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "android.arch.lifecycle:extensions:1.1.0"
implementation "android.arch.lifecycle:viewmodel:1.1.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
And here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.4.1)
include_directories(src/main/cpp/protobuf/include)
file(GLOB SRCS
"src/main/cpp/core/*.cpp"
)
file(GLOB JNI_SRCS
"src/main/cpp/jni/*.cpp"
)
add_library(mycorelib SHARED ${SRCS} ${JNI_SRCS})
find_library(log-lib log)
add_library(libprotobuf-lite SHARED IMPORTED)
set_target_properties(libprotobuf-lite
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libprotobuf-lite.so)
target_link_libraries(mycorelib
android
jnigraphics
${log-lib}
libprotobuf-lite)
Has anyone run into this problem before? Any hint on how to fix this would be greatly appreciated.
This is https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#cannot-locate-symbols.
Your protobuf library was built for a higher minSdkVersion than the rest of your app, and cannot run on the device you're using.
You need to change the version of the NDK that you are using. The article below suggests that moving to NDK 22 or newer will fix this.
unable to run on Android 6.0 after 7b77c0acedf708749b68304cc5f0ac469c9d7136

How to disable Android NDK build for some build variant

I am using Android Studio 2.2 and have setup Gradle to build c/c++ sources with NDK via CMake.
Now I would like to disable NDK build for buildType "debug". For buildType "release" I would like to keep it.
The goal is to make NDK sources compile on the build server (using "release") but disable it for developers (using "debug").
This is the build.gradle file currently in use:
android {
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
defaultConfig {
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-std=c++14"
}
}
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
}
buildTypes {
release {
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-std=c++14"
}
}
ndk {
abiFilters 'armeabi-v7a'
}
}
}
}
How can I disable NDK build (externalNativeBuild) for defaultConfig or buildType "debug"?
Other developers won't have NDK installed (local.properties without ndk.dir=PATH_TO_NDK). Is this possible to configure?
Thanks in advance
Edit:
This externalNativeBuild must be configured with a 'com.android.library'-module, not a 'com.android.application'-module.
Here is how I solved it.
This way Gradle build works for developers with and without NDK installed (and on the build server), which was the goal.
/*
* As soon as Gradle is linked to the externalNativeBuild (cmake / ndkBuild) with a path to
* CMakeLists.txt / Android.mk, the ndk.dir from local.properties file or the ANDROID_NDK_HOME
* environment variable needs to be set, otherwise gradle fails.
* E.g.:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
*/
// Only enable externalNativeBuild on machines with NDK installed -> valid ndkDir
def ndkDir = project.android.ndkDirectory;
if (ndkDir != null && !ndkDir.toString().isEmpty()) {
externalNativeBuild.cmake.path = "CMakeLists.txt"
}
Regarding #1, if I understand correctly you want to do (or skip) certain things according to the buildType. If so, you can look at one of the many discussions on this subject, such as this one: get current buildType.
Regarding #2, it is not very clear what you want. If you are seeking an alternative to setting the NDK path in local.properties, you can set it via ANDROID_NDK_HOME environment variable. If you want to prevent gradle from failing, check if the ndk.dir exists in the relevant places of your build.gradle script (using properties.getProperty('ndk.dir')).

Sonarqube task in Gradle does not produce test coverage

I have multi-project Gradle script. I added to the root project:
buildscript {
repositories{
...
}
dependencies { classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1") }
}
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.junit.reportsPath", "$projectDir/build/test-results/test"
property "sonar.host.url", "http://localhost:9000"
property "sonar.verbose", "true"
}
}
Sonarqube shows the correct number of tests, but coverage is 0.
I use Gradle 3.0, Java 1.8.0_45, Sonarqube 6.1.
Gradle console shows many "Class not found" messages.
Gradle console also shows message:
"Reports path contains no files matching TEST-.*.xml :
myPath\build\test-results\test"
, which is correct, since that particular project does not have any tests.
In my child project, I have:
apply plugin: 'java'
apply plugin: "jacoco"
jacocoTestReport {
reports {
xml.enabled = true
}
}
check.dependsOn jacocoTestReport
Run Gradle task "sonarqube" of the root project.
No SonarQube Analyzer or plugin executes your tests or the coverage calculation for you. You must do those things before analysis and feed the resulting report(s) into your analysis.

ndk-gdb with Android Studio

I was previously able to use eclipse to build an android app with ndk-build and I was able to debug using the ndk-gdb. When I do the same on the app built using Android Studio, I get this error:
ERROR: Non-debuggable application installed on the target device.
Please re-install the debuggable version!
I have set jniDebuggable=true in build.gradle:
buildTypes {
debug {
debuggable true
jniDebuggable true
}
release {
debuggable false
jniDebuggable true
}
}
Am I missing something here?
Note: I have tested on Samsung S3, Moto-g Second Generation. I tried with r9d, 10c and 10d.