targetSdkVersion gradle strange value - android

So, I cloned this project from Github and while going through its build.gradle, I found this strange configuration, particularly for targetSdkVersion. Now, before I jump into the details of what it is, let me mention that the project has two modules - app(the main one) and callrecord(encapsualting the call recording functionality)
Here is the build.gradle file for the same:
apply plugin: 'com.android.application'
android {
compileSdkVersion project.sdk
defaultConfig {
applicationId "com.aykuttasil.callrecorder"
minSdkVersion project.minSdk
targetSdkVersion project.sdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:$supportVersion"
testCompile 'junit:junit:4.12'
compile project(':callrecord')
}
Can you see it?
I don't understand the line compileSdkVersion project.sdk. This project "object" has been referenced at several other places too.
First, why would someone use this property? Second, how do I find out what version it is?

why would someone use this property?
The main purpose behind to use this property To Configure all variables for Android project modules in one place
so changing it in one place will effect in whole project
how do I find out what version it is?
it will be available in gradle.properties or build.gradle in file
have a look in Build.Gradle file of CallRecorder of that project
SAMPLE
Here is the good article on it Configure variables for all Android project modules in one place
gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX = true
android.enableJetifier = false
#gradle.properties
myTargetSdkVersion=27
myCompileSdkVersion=27
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
than use in your Build.Gradle
android {
compileSdkVersion project.myTargetSdkVersion.toInteger()
defaultConfig {
applicationId "com.example.nilesh.myapplication"
minSdkVersion project.myMinSdkVersion.toInteger()
targetSdkVersion project.myTargetSdkVersion.toInteger()
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

Related

Android Instant App with Native C++ Library not publishing to device/simulator running Android N

Is there a way to get an Android Instant App working with a native C++ library?
I'm attempting to publish an Android Instant App to a device/simulator, but ran into problems with my native C++ library. It publishes fine as an installable app, but fails to find the library when published as an Instant App.
To eliminate any other issues, I started a new project in Android Studio 3.0 (Canary 1 171.4010489) with the new project wizard and selected the following settings:
First Page:
Include C++ support checked
Second Page:
Phone and Tablet selected
Include Android Instant App support checked
Sixth Page:
C++ Standard set to 'C++11'
Exceptions Support (-fexceptions) checked
Runtime Type Information Support (-frtti) checked
The resulting project will publish as an installable app (showing the 'Hello from C++' screen), but not an instant app... it gives the following error that it can't find the library, which is the same error I get in my actual app's project:
couldn't find "libnative-lib.so"
Full error:
05-24 17:48:30.316 7519-7519/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany.instantapp, PID: 7519
java.lang.UnsatisfiedLinkError: byc[DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.mycompany.instantapp/atom-download--feature-1495662507463/feature.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.mycompany.instantapp, /system/lib, /vendor/lib]]] couldn't find "libnative-lib.so"
...
I'm pasting the relevant gradle files below (all generated by Android Studio):
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
defaultConfig {
applicationId "com.mycompany.instantapp"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':feature')
implementation project(':base')
}
base/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
feature/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':base')
testCompile 'junit:junit:4.12'
}
instantapp/build.gradle:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':feature')
implementation project(':base')
}
Updates:
I've filed an issue with Google:
Link: Google Issue Tracker
Though I feel like the tools to make this happen are already available (Gradle, CMake, NDK, etc)
Also thanks #Anirudh for letting me know that this is a known issue on Android N.
Does publishing an Instant App with no C++ library work on my device?
Yes... if I create a new Android Studio project with only Include Android Instant App support it publishes to my Samsung Galaxy 7S and shows the 'Hello World!' screen.
Does publishing a signed APK work?
Generating a signed APK works, and upon inspection the native C++ library is bundled with the feature-debug.apk but not the base-debug.apk. This is what I would expect given the gradle configuration, but doesn't explain why it won't publish to a device/simulator.
I haven't tried sideloading these APKs... but I'm skeptical if that is even possible given that the Instant App is never installed... ex: how would you even launch it after sideloading it (click a url?)
Does adding the C++ library to both APKs work?
I've tried adding the externalNativeBuild gradle properties to both the base/build.gradle and the feature/build.gradle files, but the same error still occurs. I verified that the native C++ library is then included in both APKs by inspecting both the feature-debug.apk and the base-debug.apk after generating a signed APK.
modified base/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "../feature/CMakeLists.txt"
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Does publishing a signed APK work?
Android Studio 3.0 preview Generate Signed APK feature has a bug currently where the final zip doesn't include all feature apks. Use Gradle SigningConfig in each feature module's gradle file to sign your feature apks
Does adding the C++ library to both APKs work?
Not required. Adding to base feature apk should be enough
The actual crash is known issue with NDK support for Android Instant Apps on Android M/N. The app works on Android O emulator

In Android Studio what is the equivalent of CMAKE_VERBOSE_MAKEFILE under ndk-build?

I am trying to push some existing Android.mk-based native code into a new Android Studio app. There are some linking errors that give the message "Error:error: linker command failed with exit code 1 (use -v to see invocation)". When using CMake, one can set the variable CMAKE_VERBOSE_MAKEFILE to make this the default behavior. Is there a way to do something similar under ndk-build? Trying to run ndk-build from the command line with -v or V=1 (not sure which is best) in an Android Studio context seems awkward.
Edit:
As noted in the response below, this should be possible from Gradle using the "arguments" keyword. My interpretation of this is this version of the Module: app build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.adth.jwc.testproj4"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
ndkBuild {
path "$projectDir/jni/Android.mk"
arguments "V=1"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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'
}
This generates the error message "Error:(16, 0) Could not find method ndkBuild() for arguments [build_95llvy1tc979yxena3spokoe8$_run_closure1$_closure3#34646897] on root project 'TestProj4' of type org.gradle.api.Project."
I have also tried some variations, all of which generate essentially the same error. What is the correct placement of the "arguments" keyword in the build.gradle file?
From the DSL reference, it looks like you need to put the exernalNativeBuild block in a product flavor or build type block to add arguments, so
defaultConfig {
applicationId "com.adth.jwc.testproj4"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild {
arguments "V=1"
}
}
}
should work. Confusingly, BaseExtension (the android block) can also have an externalNativeBuild block, but its ndkBuild property is an NdkBuildOptions object, which only has a path property. The ndkBuild blocks for flavors and build types are ExternalNativeNdkBuildOptions objects, which have arguments etc.
ndkBuild { arguments "V=1" } in your build.gradle, and then run gradle with --info (Settings->Build, Execution, Deployment->Compiler->Command-line Options).
For command line ndk-build usage, run ndk-build V=1.
https://developer.android.com/studio/projects/add-native-code.html#link-gradle

Could not find method apply() for arguments

I have followed many solutions just to get this to run and have wound up here, but do not know what else to do.
How can I configure this project to run?
build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
//兼容Android6.0系统所需,如果这句话报错,可在dependencies标签下使用compile 'cn.bmob.android:http-legacy:1.0'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.htq.baidu.com.htq.baidu.coolnote"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
//minifyEnabled false
// signingConfig signingConfigs.release
// minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main() {
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
ignoreWarnings true
//lint 遇到 error 时继续 构建
abortOnError false
//build release 版本 时 开启lint 检测
checkReleaseBuilds false
// 防止在发布的时候出现因MissingTranslation导致Build Failed!
disable 'MissingTranslation'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'cn.bmob.android:http-legacy:1.0'
compile 'cn.bmob.android:bmob-sdk:3.4.7-aar'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.github.clans:fab:1.6.1'
}
apply plugin: 'groovy'
apply plugin: 'groovy'
setting.gradle
include ':app'
local.properties:
sdk.dir=D\:\\Android\\sdk
gradle.propertes:
#Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html
#sec:decoupled_projects
# org.gradle.parallel=true
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
I installed them in C:\Users\lwy.gradle\wrapper\dists:
I have solved this problem! Here is my may:
1.copy the contetn of "build.gradle",then delete the "build.gradle";
2.create a new build.gradle and paste the previous content to this "build.gradle"
That's all !
It happens when u save the file as a unicode format. So copy the contents in other file and delete the older one.
as for me , change the file encoding from UTF-8 BOM to UTF-8, it solve my problem.

Android project Gradle and Jack Build Toolchain : The import cannot be resolved

I have an Android project and I use Android Studio. In this project, I have the main app (cdmandroidclient) and the SDK (cdmsdk) which is the core lib.
I added recently a library built with Java 8 into my Android project. So I had to change a few things into my Gradle files :
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.mycompany.cdmandroidclient"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(path: ':cdmsdk')
compile 'com.android.support:appcompat-v7:24.2.0'
}
As you can see, I import into my app, the cdmsdk module, which is part of my project. Before using Jack, everything was fine.
Now, when I try to build the app I get errors for resolving dependencies of my module "cdmsdk" into my app "cdmandroidclient".
Exemple of an error :
Error:E:\Workspace\CDMAndroidClient\app\src\main\java\com\mycompany\cdmandroidclient\service\CdmService.java:16:
The import com.mycompany.cdmsdk.heartbeat.Security cannot be resolved
I don't understand what's happening, because the main app dependencies have not changed and still reference the SDK with :
compile project(path: ':cdmsdk')
The Gradle build fail as I said, during the task :app:compileDebugJavaWithJack
Any idea ? Thank you very much :) !
EDIT : It's the exact same thing as Javac and with Java 7... don't know what I've changed but my app can't use cdmsdk dependencies anymore ... wtf

To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB

Actually the main error is "java.exe finished with non-zero exit value 1". First i tell you every problem which i faced after installing studio:
Three days ago, i just installed android studio & I created new project.
1) First it throw the error "Plugin is too old, please update to more recent version", after searching on google i changed
classpath : com.android.tools.build:gradle:2.0.0-alpha2
to
classpath : com.android.tools.build:gradle:2.0.0-alpha8
Current Error solved.
2) After that it was asking for gradle 2.10, i updated this one also & set the path.
Current Error solved.
3) When i ran my application i got one more error "app-debug-unaligned.apk, specified for property 'input file' does not exist".
I searched on internet, i got one solution on stackoverflow. So as answer on stackoverflow i go to "Build" & i selected build apk.
Current error solved.
4) But after that again i got one error
"To run dex in process, the Gradle daemon needs a larger heap. It currently has 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 1G.
java.exe finished with non-zero exit value 1".
I have been searching on stackoverflow for last three days, i applied each and every answer one by one but i'm not able to solve the error. Please save my life, i am really tired of this problem. I show you image what error is coming exactly
My build.gradle file
apply `plugin: com.android.application`
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "java.danish.org.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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'
}
I updated everything SDK platforms & SDk Tools.
Please tell me what i am doing wrong here.
Issue
In gradle plugin version 2.0.0-alpha7 and -alpha8 Dex runs inside gradle build process as opposed to a separate process.
Option a)
Change gradle plugin version to 2.0.0-alpha9 where in-process Dex is disabled by default.
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
Option b)
Disable in-process dex in your app module build.gradle:
android {
// ...
dexOptions {
dexInProcess = false
}
}
Option c)
Increase memory available to gradle process.
Create or update gradle.properties file in your project root directory:
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m
And update your app module build.gradle file:
dexOptions {
preDexLibraries true
javaMaxHeapSize "3g"
incremental true
dexInProcess = true
}
These values are experimental and work for my setup. I use 3 GB for dex and 4 GB for gradle (3 + 1 GB).
Note
If you have any issues update to alpha9 anyway.
I found the solution.
Changes
1)
dexOptions {
javaMaxHeapSize "4g"
}
2)
lintOptions {
checkReleaseBuilds false
abortOnError false
}
This is my new build.gradle and everything is working fine now.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc4"
dexOptions {
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "com.aquasoft.guesp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.squareup.picasso:picasso:2.5.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:design:23.4.0'
compile 'com.stripe:stripe-android:+'
compile 'com.roomorama:caldroid:3.0.1'
compile 'com.android.support:cardview-v7:23.3.+'
}
try this gradle params
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}

Categories

Resources