Gradle: sourceSets not working as expected - android

Gradle: sourceSets not working as expected.
Here is my code:
android {
...
defaultConfig {
applicationId "com.firsthash.smartyoutubetv2"
minSdkVersion 14
targetSdkVersion 25
versionCode 111
versionName "6.8.39"
multiDexEnabled = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/res-exoplayer', 'src/main/res-xwalk', 'src/main/res-webview']
}
debug {
res.srcDirs = ['src/main/res', 'src/main/res-exoplayer', 'src/main/res-xwalk', 'src/main/res-webview']
}
}
productFlavors {
full {
}
beta {
applicationIdSuffix ".beta"
}
}
}
The problem. Everything goes ok until I try to do an update of any project's layout file. All changes that I've made didn't reflected on the final application. I figured out that to obtain right behavior I need to manually delete project's 'build' directory. This directory contains cached build files. Such happens when I built apk using 'gradle: installDebug task' or Android Studio internal build system.
UPD: best workaround that could find is to use flavor dimensions: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-flavor-variants

Related

More than one file was found with OS independent path 'lib/armeabi/libBugly.so'

I tried to debug my application, but an error appeared:
More than one file was found with OS independent path 'lib/armeabi/libBugly.so'
This is a part of my gradle:
android {
compileSdkVersion 26
dataBinding {
enabled = true
}
defaultConfig {
multiDexEnabled true
minSdkVersion 15
targetSdkVersion 26
versionCode 3
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
}
}
dependencies {
implementation 'com.tencent.bugly:crashreport_upgrade:latest.release'
implementation 'com.tencent.bugly:nativecrashreport:latest.release'
}
Android Studio 3.1.3, Gradle4.1 in my project.
Add something in app's build.gradle :
android {
packagingOptions {
pickFirst 'lib/armeabi/libBugly.so'
}
}
Then, it works.

Why can I see server response in my signed apk android?

I generated a signed apk using a .jks file for release.
It got uploaded on playstore for beta testing also. But if I use the app with my andorid-studio I can see the server responses in my log-cat which should not be the case as far as I know.
When I generate the apk, i can see the build type release
and my build.gradle of module is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "PACKAGE_NAME"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
multiDexEnabled true
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/res/menu']
java.srcDirs = ['src/main/java', 'src/main/java/2', 'src/main/java/PACKAGE_NAME/Models']
}
}
productFlavors {
}
}
Can anyone explain?
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
You can use your logs like below
public class AppLog {
public static void info(String tag, String message) {
if (BuildConfig.DEBUG) {
Log.i(tag, message);
}
}
}
Refer : https://developer.android.com/reference/android/util/Log.html

My R in library is red but I can build and run app normally

I use compile project(':pickphotos') to include a library named pickphotos.
The R in pickphotos is red though I have me.crosswall.photo.pick.R.I can build and run the app normally.
When I use Alt+Enter , it shows some solution:
When I use Move 'R' in pickphotos, it shows some R:
But if I pick me.crosswall.photo.pick.R,I will get repeat R error in my next build.
Below is the build.gradle of pickphotos:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
}
I can also find it app/build/generated/source/r:
There is no Mark as item in menu in Android Studio:
I finally resloved it.
Just Make Project.
R is created when Make Project.
I think when we Run Project or Build Project,Android Studio doesn't Make Project for some reason.
Going to Build > Rebuild Project and/or Clean Project seems to be the goto first attempt at fixing any mindboggling red errors. Better to do that then spend 45 minutes staring at code trying to figure out what's wrong when the answer turns out to be 'nothing'...

Android: Organize layout folder

How could I organize my layout folder in Android Studio? I want to add subfolders to it.
I followed this question but nothing happens when I modify my gradle file. As I see a lot of up votes I think it works, but I can't figure out how and why it doesn't work for me. I cleaned project, restart Android Studio, invalidate caches but still nothing.
It's so strange It doesn't work. Let me show you how I build my Gradle (the part where you set dependencies):
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.yourapp"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/activities',
'src/main/res/layouts/fragments',
'src/main/res/layouts/content',
'src/main/res/layouts',
'src/main/res'
]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {....
and that's It.
Hope I've been helpful.

Building flavors and defaultConfig using play button in Android Studio

I have created the following gradle.build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName '1.0'
applicationId 'com.kibo.mobi.app'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flavor1{
applicationId 'com.kibo.mobi.flavor1'
minSdkVersion 14
targetSdkVersion 20
}
flavor2{
applicationId 'com.kibo.mobi.flavor2'
minSdkVersion 14
targetSdkVersion 20
}
}
sourceSets {
flavor1{
manifest.srcFile 'flavor1/AndroidManifest.xml'
assets.srcDirs = ['src/flavor1/assets']
}
flavor2{
manifest.srcFile 'flavor2/AndroidManifest.xml'
assets.srcDirs = ['src/flavor2/assets']
}
}
}
dependencies {
compile project(':AppSDK')
}
Pressing the Play/Run button in Android Studio results in building, compiling and installing the "flavor1" version on the connected device.
How can I manually configure what version will be installed? When the default version (not a flavor - but the "main" folder) is also a version I need to install sometimes. So basically there are 3 version here that I need to have the ability to install each one of them as requested.
The "Build Variants" tool window (View menu > Tool windows > Build variants) lets you select which flavor + build type combination will be built and run by default.

Categories

Resources