Android: Organize layout folder - android

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.

Related

Android app is not building after change the android studio version

I created an Android app using the android studio (2016) with the following parameters
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.2.1'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.stl.sciocardio.app.androidapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Also, I use third party projects inside the project as well. When I change the Android studio 2020 the app is not built or even not detected as an android project. It gives me the following error once I try to rebuild it
Unable to find Gradle tasks to build: [:app, :, :GraphView-master].
Build mode: REBUILD.
Tests: None.
How can I fix the issue?
Try this:
Delete folders [build, .idea, .gradle]
Invalidate Caches / Restart
If it does not get resolved, then repeat the above step by removing
include ':app' from settings.gradle

android.content.res.Resources$NotFoundException Error in Marshmallow only, but working properly in Nougat

android.content.res.Resources$NotFoundException Error in Android M only ,working proper in Android N.When i remove vectore drable file its work fine
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
buildToolsVersion '27.0.2'
defaultConfig {
applicationId "com.h8.subscriber"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
generatedDensities = []
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig getSigningConfig()
}
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Well I had the same problem. The image resource was not working on Marshmallow.
My problem was that the image was actually in drawable-v24, and not in drawable folder.
U can also check with this. if the image is in v24 it will be shown in the resource folder(underlined with red in the image provided).
Change it from v24 to the normal drawable folder and you are done.

Can't load AppCompat ActionBar with the unknown error.Android Studio 3.1.3

I'm facing this problem even when I tried switching from
com.android.support:appcompat-v7:28.0.0-alpha 3 to
com.android.support:appcompat-v7:28.0.0-alpha 1.
It works, but after adding some new activities it causes the same problem. I went to Invalidate caches/restart and restart my Android studio but it didn't work...
Please any expert who help me thanks... I'm really in trouble for the last couple of days.
Use the previous gradle version 27, and change your project gradle config to this. The new alpha-one might cause problems with new activities sometimes.
Just clean and rebuild after gradle sync.
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.package.name"
minSdkVersion 22
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-compat:27.1.1'
implementation 'com.android.support:design:27.1.1'
}

Gradle: sourceSets not working as expected

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

android - textView textColor not taking effect on device

I have a layout like this. Here I set the textColor to red.
When I run this on emulator, everything works as expected. However, when I run on device, textColor is white. It used to work on device.
I did lot of code refactoring with emulator. I might have changed something that could lead to this issue. I was hoping if someone else has encountered a similar issue.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EXAMPLE"
android:textColor="#color/red"
android:textSize="60sp" />
What could be the issue?
android {
dexOptions {
javaMaxHeapSize "6g"
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
defaultConfig {
applicationId "someID"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
productFlavors {
dev {
minSdkVersion 15
}
prod {
minSdkVersion 15
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
I resolved this issue by cleaning all build directories and clean/rebuild.
I also removed productflavors/devDebug from .gradle. That must have caused the issue as I was it was configured for minSDKVersion 15 and I was trying to run on 22.
From Android docs:
android {
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
...
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}

Categories

Resources