Create New Folder in Android Studio is empty (nothing here) - android-studio

Resume:
Normally in Android Studio when you right click on a SRC directory, the menu NEW> FOLDER> have many options like: AIDLS Folder, Assets, INI, JAVA, etc:
New>Folder>Option example
My is empty (see last image bellow).
Theory:
I have created two product flavors in my in my Build.Gradle:
flavorDimensions "version"
productFlavors {
free {
applicationId "com.xxxx.yyyy.free"
versionName "1.0-free"
buildConfigField "boolean", "PAID_VERSION", "false"
dimension "version"
applicationIdSuffix ".free"
versionNameSuffix "-free"
}
full {
applicationId "com.xxxx.yyyy.paid"
versionName "1.0-full"
buildConfigField "boolean", "PAID_VERSION", "true"
dimension "version"
applicationIdSuffix ".full"
versionNameSuffix "-full"
}
}
When you create a new product flavor, Android Studio doesn't create the source set directories for you, but it does give you a few options to help you. For example, to create just the java/ directory for your "debug" or "release" build:
Open the Project pane and select the Project view from the drop-down menu at the top of the pane.
Navigate to MyProject/app/src/.
Right-click the src directory and select New > Folder > Java Folder.
From the drop-down menu next to Target Source Set, select debug or release.
Click Finish.Android Studio creates a source set directory for your debug build type, and then creates the java/ directory inside it.
(Ref. https://developer.android.com/studio/build/build-variants?utm_source=android-studio#product-flavors)
Problem:
As you can see in the following image, my Folder options is empty. Can anybody explain me why?

Solved: The folder options came back after restarting Android Studio and Rebuild the Project. Can’t simulate back the case and the real reason it’s unknown to me or it’s an Android Studio 3.2.1 bug.

Related

How do I exclude a folder from the sidebar in Sublime Text permanently, specifying it relative to the open folder?

I've already read this related question (How do I exclude a folder from search in sublime text 3 permanently?) but my question is different since I want to specify only the folder at the open folder's root, not a generic pattern to match at any level in the folder tree.
In Sublime Text 4 I have an open project folder via File --> "Open Folder...".
Let's say my folder layout is this:
mainapp
├── microapp
│ └── node_modules <== don't exclude this (keep it)
├── microapp2
│ └── node_modules <== don't exclude this (keep it)
├── index
├── node_modules <=== exclude this only
├── config
└── assets
I'd like to exclude mainapp/node_modules only, NOT mainapp/microapp/node_modules nor mainapp/microapp2/node_modules. How do I do that?
I'm guessing I need to specify a "folder_exclude_patterns" in the settings.
Side note: why do I need to do this?
Because that folder has so much build content in it (which is constantly-changing as builds occur) that it's actually causing Sublime Text to freeze and lock up and become unusable.
Tested on Linux Ubuntu 18.04.
Through sheer dumb luck and persistence with guessing, I figured it out. // refers to the "open folder root", apparently.
If you want to see this info about // added to the official Sublime Text documentation and default settings file, please upvote my open issue on it here.
Update
I found some official documentation on this: https://www.sublimetext.com/docs/file_patterns.html. The // feature was added as of Sublime Text 4:
If pattern begins with //, it will be compared as a relative path from the project root [added in version 4.0]
My testing, however, proves that the // actually means "path" root, as defined below, however. So, my examples below are still correct.
1. If you have a folder open via File --> "Open Folder...", do this:
Preferences --> Settings --> add this "folder_exclude_patterns" entry to your user settings JSON file:
{
// other user settings here
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
// other user settings here
}
Again, // means the "open folder's root".
NOTE: Changing your user settings above will apply globally to all of your Sublime Text instances, which may not be what you want. So, it may be better to use a "Project" instead, as described below:
2. If you have the folder open and saved as part of a project, do this:
Project --> Edit Project --> add this "folder_exclude_patterns" entry to your Project settings JSON file:
{
"folders":
[
{
// path to an open folder in a project
"path": "/path/to/mainapp",
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
}
],
}
You can see in the official project settings file example here (https://www.sublimetext.com/docs/projects.html) that the "folder_exclude_patterns" entry must be at the same level in the JSON settings file as the "path" entry.
I also first learned this from #smhg's comment here. Thank you!
To open another folder in your project, go to Project --> "Add Folder to Project...". Once you have multiple folders open in your project, you'll have to add multiple entries of "folder_exclude_patterns", as desired, like this:
{
"folders":
[
{
// **absolute path** to open a folder in a project
"path": "/path/to/mainapp",
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
},
{
// or **relative path** to open another folder in the project;
// the path is relative to the location of the
// "project_name.sublime-project" project file itself
"path": "some_dir",
// exclude only the "some_dir/path/to/excluded_folder" dir
"folder_exclude_patterns": ["//path/to/excluded_folder"],
},
],
}
Bonus: How to create a project in Sublime Text:
To create a Project from an open folder, the steps are like this:
Open a folder: File --> "Open Folder..."
Save it as part of a project: Project --> "Save Project As..."
Now you can choose where to save your project_name.sublime-project file. This is the file you are editing when you go to Project --> "Edit Project" above. To open a project go to Project --> "Open Project...".
See also:
Issue I opened: https://github.com/sublimehq/sublime_text/issues/5234
Comment I wrote on the Sublime Text forum: https://forum.sublimetext.com/t/a-way-to-specify-root-in-project-settings/7756/4?u=ercaguy
Official Project settings documentation: https://www.sublimetext.com/docs/projects.html. This includes:
Each object must have a "path" key, which may be relative to the project directory, or a fully qualified path.
How do I exclude a folder from search in sublime text 3 permanently? - answer which explains how to exclude a file or folder from the side bar in Sublime Text, versus excluding a file or folder from search, such as Goto Anything or Find in Files.

How to clear specific gradle cache files when running the "Clean project" command?

I have added the following task in my project's build.gradle file:
task('clearLibCache', type: Delete, group: 'MyGroup',
description: "Deletes any cached artifacts with the domain of com.test in the Gradle or Maven2 cache directories.") << {
def props = project.properties
def userHome = System.getProperty('user.home')
def domain = props['domain'] ?: 'com.test'
def slashyDomain = domain.replaceAll(/\./, '/')
file("${userHome}/.gradle/caches").eachFile { cacheFile ->
if (cacheFile.name =~ "^$domain|^resolved-$domain") delete cacheFile.path
}
delete "${userHome}/.m2/repository/$slashyDomain"
}
I'd like this task to be executed when I hit the "Clean project" menu, and only in this case.
How to do that ?
That "Clean project" menu item under the hood appears to do a couple of things (based on the output of the Gradle Console window when you click it):
A gradle clean, the equivalent of calling ./gradlew clean
Generate sources and dependencies for a debug build, including a mockable Android sources jar if needed.
I would make your task a dependency for the Gradle clean task, so that whenever the project is cleaned, this task is also invoked. This can be achieved by adding the line clean.dependsOn clearLibCache in your build.gradle after you declare the task.

Android Studio shows inexplicable warnings for build.gradle

I've created an Android library project in Android Studio and prepared the build.gradle to automate deployment to the Maven Central repository, followed the official instructions from Sonatype.
Particularly, I've added metadata according the Metadata Definition and Upload section
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
//...
pom.project {
name 'Example Application'
description 'A application used as an example on how to set up pushing its components to the Central Repository.'
url 'http://www.example.com/example-application'
scm {
connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
url 'http://foo.googlecode.com/svn/trunk/'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'manfred'
name 'Manfred Moser'
email 'manfred#sonatype.com'
}
}
}
}
}
}
Android Studio shows warnings like 'name' cannot be applied to '(java.lang.String)' for the entries
pom.project/name,
pom.project/description,
pom.project/licenses/license/name,
pom.project/organization/name and
pom.project/developers/developer/name.
Running ./gradlew --info clean uploadArchives shows no such warnings. The generated pom.xml contains the defined metadata.
These warnings are somewhat annoying, because Android Studio intercepts every commit that includes the build.gradle to inform me about the existence of warnings.
The question: It there actually a problem with the build.gradle or is there something wrong with Android Studio's interpretation? If it is a problem with the build.gradle, how do I fix it?

Android Studio: How to exclude Icon\r file?

Google Drive automatically generates Icon$'\r' in each synced folder in OSX. I'd like to exclude this file Icon$'r' recursively from compilation in Android Studio.
I tried #1 (din't work):
Adding !/**/Icon$'\r' and !/**/Icon' in the following field:
File -> Other Settings -> Default Settings
Build, Execution, Deployment -> Compiler
Resource patterns:
I tried #2 (didn't work):
Adding the following in build.gradle under module:
sourceSets {
main {
java {
srcDir 'src'
exclude '**/Icon$"\r"'
// exclude '**/Icon'
}
}
}
Note:
I already excluded Icon$'\r' in .gitignore
If Icon$'\r' is both excluded at compilation AND hidden, that'd be the best solution.

installation failed since the device possibly has stale dexed jars that don't match the current version (dexopt error)

I am unable to run app from android studio to my samsumg phone running android 2.3.6. I am getting Application installation Failed popup refer below screenshot.
when I click on OK I get below error in log
Failure [INSTALL_FAILED_DEXOPT]
DEVICE SHELL COMMAND: pm uninstall my.package.name
Unknown failure
I got in this trouble after adding Google Cloud Module called "App Engine Backend with Google Cloud Messaging".
This is exactly same problem described in one of stack overflow questions here
I tried the accepted answer.
Ran dex-method-counts application I got "Overall method count: 24474" in terminal. I dont understand what to do next?
(Note : The same application is running on my other device running on kitkat.)
Please help to resolve this issue. I am struggling from past two days. I know there are many similar questions but nothing helped me.
Built--> Clean is not working.
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "my.package.name"
minSdkVersion 9
targetSdkVersion 19
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/libGoogleAnalyticsServices.jar')
compile project(path: ':gcmAppEngineBackend', configuration: 'android-endpoints')
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
}
Thanks in advance!
This usually happens because your device doesn't have enough space in memory.
Delete some apps and try again
When i got this error, i was using a Nexus 4 in the AVD-Manager. By default this device was created with 500MB internal storage.
I increased the storage to 2048MB and the "stale dexed" error was gone.
To increase the internal Storage:
Go to ADV-Manager
Select the Edit Button of the corresponding device under "Actions"
Click "Show Advanced Settings"
Increase your internal Storage
In case it's an Android Emulator giving you a "stale dexed" message, this helped for me on a Mac:
stop emulator
cd ~/.android/avd/[emulator name].avd
rm *.lock
wipe emulator
start emulator
I solved this by Wiping data .
Android Studio -> AVD Manager -> Actions -> Wipe Data
It seems like your emulator low on disk space. But after you increase your disk space you still get error.
I faced the same problem, increase disk space and do factory reset for the emulator worked as well for me. To reset your emulator go to Settings -> Backup and Restore inside the emulator then reset.
Disable Instant Run.
Android Studio -> Preferences -> Instant Run
Also I have the same problem. To make it work I had to remove "third party library" from dependencies.
Or try this: https://developer.android.com/tools/building/multidex.html
Replace this 'compile files('libs/libGoogleAnalyticsServices.jar')' with this 'com.google.android.gms:play-services-analytics:8.3.0'

Resources