Android Studio "Project Structure" window not working? - android

Loads of tutorials for Android Studio need me to use the "Project Structure" window (File > Project Structure), but whenever I try to open it, I get an error "We will provide a UI to configure project setting later. Until then, please manually edit your build.gradle file(s.)".
Does anyone know if it's like this for everyone (in which case, what do those tutorials mean by File > Project Structure?), or just me? I've had the same error on Windows and Linux.
One of the tutorials: How do I add a library project to Android Studio?

Before Android Studio, IntelliJ Android plugin users used to use the Project Structure dialog to add/remove modules from their projects.
Android Studio aims to have a single model for building your application from both the command line and from the IDE. So if you have to modify the project structure, the correct way to do it is to modify your build.gradle (and/or settings.gradle) build scripts and reimport the project.
Eventually (within a few months), Android Studio will hook up the project structure dialog to automatically edit the gradle build scripts for you, or will provide a different UI, just like the error message says.
You'll find the gradle plugin user guide at http://tools.android.com/tech-docs/new-build-system/user-guide to be helpful in figuring out how to add libraries to your gradle build scripts.

There are currently some bugs with the UI in android studio project structure settings related to updating the Gradle. Right now whatever I enter into the project structure fields do not save or update the gradle files. What did work for me was writing the settings directly into the build.gradle
The gradle files are basically xml files that are generated (dynamic) instead of static.
I tried forever in the project structure UI to set up application signing for debug, eventually to get it to work I added,
android {
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
foo {
signingConfig signingConfigs.myConfig
}
}
}
The android developers guide for configuring gradle will help you get up to speed.
http://developer.android.com/tools/building/configuring-gradle.html
refer to the Gradle documentation for the parameters you are looking for
http://tools.android.com/tech-docs/new-build-system/user-guide

There are currently some bugs with the UI in android studio project structure settings related to updating the Gradle. Right now whatever I enter into the project structure fields do not save or update the gradle files. What did work for me was writing the settings directly into the build.gradle
The gradle files are basically xml files that are generated (dynamic) instead of static.
I tried forever in the project structure UI to set up application signing for debug, eventually to get it to work I added,
android {
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
foo {
signingConfig signingConfigs.myConfig
}
}
}
The android developers guide for configuring gradle will help you get up to speed.
http://developer.android.com/tools/building/configuring-gradle.html
refer to the Gradle documentation for the parameters you are looking for
http://tools.android.com/tech-docs/new-build-system/user-guide

Related

Unable to switch to debug build variant in Android Studio

I've switched to release build variant and configured signingConfigs. Now when I try to check the debug build variant from the drop down menu it switches immediately back to the release build variant. So I'm not able to run my app in debug mode any more.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
signingConfigs {
config {
...
}
}
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.kost.foo"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
externalNativeBuild {
cmake {
...
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
signingConfig signingConfigs.config
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main {
jniLibs.srcDirs = ['src/main/jni']
}
}
externalNativeBuild {
cmake {
path 'src/main/jni/CMakeLists.txt'
}
}
}
kapt {
generateStubs = true
}
repositories {
maven { url 'https://github.com/linchaolong/stetho-realm/raw/master/maven-repo' }
mavenCentral()
}
I've tried to revert all changes in build.gradle as it was before configuring, but with no luck.
Any ideas how to fix the issue?
I had a similar problem where most of the Build menu items were greyed out.
'Sync project with Gradle files' didn't fix.
I noticed a 'Build Variants' toggle button on the bottom left of Android Studio (v 3.1.2) and with this was finally able to choose the variant I needed.
Maybe this will work for you too.
Maybe you have got your solution to this, just in case, i provide my solution here.
For Android Studio 2.x
It may because that you compile your dependent project using:
compile project('module_a')
Above setting will force your project to compile the release version of your modules. Just change it to below:
releaseCompile project(path: ':module_a', configuration: 'release')
debugCompile project(path: ':module_a', configuration: 'debug')
For Android Studio 3.x
You don't need to explicitly specify the build variant for a "module project". Just using
implementation project(':library')
will automatically help select the correct build variant.
Here is a detailed explanation: https://developer.android.com/studio/build/?utm_source=android-studio#variant_aware
For Android Studio 3.x Upgraded from 2.x
Delete the .idea folder under your project root directory and restart your Android Studio.
Below is the GUI screenshot:
Hope it helps!
Just need to cut ".idea" Folder and paste it outside Project root folder( For Back up if you need).These files will be auto regenerated. On Opening the project it"ll ask add module (app) to your project. You can ignore the same.
It set set default build variant to be "debug".
You can see build variant tab on left corner or hover on "Monitor" Symbol on left bottom to get build variant option.
I just had the same issue. Solved it by closing Android Studio, removing the generated files and folders: .gradle, .idea, app/.externalNativeBuild, app/build, build, app/app.iml, ProjectName.iml, local.properties, then relaunching Android Studio and allowing it regenerate all these files from scratch.
Had the same problem, solved creating a new temporary Build Type, Build > Edit Build Types, select Build Types and add a new one. Sync, then you can select the new build type, and then revert back to original Debug build type.
Open your module setting. (Click F4)
Go to build types and create a new Build by clicking on plus(+) sign.
Name it anything, like "demo".
Duplicate all the data of debug build.
Now when you open Build Variant you will be able to switch to Debug as well as Demo.
For me I was unable to switch to our 'devDebug' variant but I could switch to another variant like 'devRelease' and then 'devDebug'. So try switching to another variant first.
I ran into a similar issue. My module level build.gradle reflected configurations specified for "debug" AND "release" accordingly. I was able to successfully run my app on emulator and device (LG) prior To Building and Signing My Release Version Of My App. After Building and Signing The Release Version and attempting to Run The Signed APK on My Phone and Device, i received an Error PM Session 'mobile': Error Launching activity....Error while Launching activity..So I started retracing my steps and realized that before deploying the signed release variant, i opened up the run/debug Configurations Dialog
and mistakenly selected the the Value APK from app bundle value From The Deploy attribute, under the Installation category
I Signed My APK In its ENTIRETY and NOT Via Bundle, so the option selected was attempting to Deploy an invalid App Bundle That Was Never Generated To Begin With, even if it was for the correct Build Variant.
I have this question too. My solution is checkout to the branch which i had changed the build variants. And at that branch, I can change from release back to debug. Then just checkout to current branch and everything is OK. It seems to be a Android Studio bug.
English is not my native language; please excuse typing errors.
I also meet this situation. i do this to solv .
Solv:
1. delete each module's impl suffix type file and build folder;
2. then click this button to sync project with gradle build file. button position
finally. and then this problem will be fix.
I fixed this issued by:
Add a new build type named debug1 via edit build.gradle;Enable debug function of this build type;
Sync and select the new build type debug1;
This issue seems to occur when opening the project in a symlinked location on linux. Opening the project directly fixed this issue for me.
relevant link: https://issuetracker.google.com/issues/156857164
For me, it was an issue with the gradle version. Make sure your plugin version and the required gradle version fit together, as defined here.
https://developer.android.com/studio/releases/gradle-plugin
You can find out which gradle versions you are using under:
File -> Project Structure... -> Project
I tried all the above to no effect. Eventually stumbled across File > Invalidate Caches/Restart... for other reasons and found it worked for me.
in main root of app in build.gradle
replace it from:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
to my Android Studio v3.0.1 in my case:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
March 26, 2021:
Would not switch from Release to Debug,
File | Invalidate Caches fixed it for me
Unrelated to your build.gradle file,
Sharing hoping it might help someone else -
I was having similar issue it was because one of the line in build.gradle -
android {
...
publishNonDefault true // remove this line and it should work!
}
Here you can get more detail about publishNonDefualt -
It is also possible to publish all variants of a library. We are planning to allow this while using a normal project-to-project dependency (like shown above), but this is not possible right now due to limitations in Gradle (we are working toward fixing those as well).
Publishing of all variants are not enabled by default. The snippet below enables this feature:

Sign my android app when building with Android Studio

I just converted my Eclipse project to an Android Studio project.
One of the very important step in the building/running process is to sign the apk.
So I used the "generate signed apk" from the build menu and it worked fine.
Now, I just want that when I run the app on the USB device, the signing is done automatically. The Android Studio page state that it's possible using the "signing" tabs in the module settings but this tabs doesn't exist!! See the picture below:
I have the latest version of Android Studio, so I guess this feature moved somewhere else but I can't find it!
Thanks!
The menu is under File > Project Structure. Then select your module from the list on the left, switch to the signing tab, and add your signing information.
This will make two changes to your build.gradle:
First, it will add a signingConfigs {} section that looks something like this-
signingConfigs {
release {
storeFile file("your.keystore")
storePassword 'mySecreKystorePassword'
keyAlias 'myKeyAlias'
keyPassword 'mySecretKeyPassword'
}
}
Second, it will configure your buildTypes to use this signing config like so-
buildTypes {
release {
signingConfig signingConfigs.release
}
Usually there're good reasons to have separate debug and production builds (e.g. separate API endpoint, separate API KEYS on tracking, faster building times), so I'll leave a question here for you: Why do you want to debug using a signed (a.k.a. production) build?
on the other hand, to answer your question, there's an easy way to switch which build variant that will be used when you hit the play button on AndroidStudio.
On the several panels around the border there's one named BuildVariants with a little Android icon. Over there's a drop-down menu where you can change to use debug or release build variant.

Using Android Studio how do I get a signed, non-debug and zip aligned APK?

Using Android Studio how do I get a signed, non-debug and zip aligned APK?
So far I can get a signed one but it gets rejected because it has debugging in it.
I can get a non debug release apk but it gets rejected because it's not zip aligned.
I can zip align it but then I can't upload it because that one is not signed.
Edit: I should mention that I'm on windows. Most everything I've looked at is linux based and difficult to separate linux paths from config paths.
Edit2: Things are on hold at the moment. I updated Android Studio and that killed everything because it comes with gradle 1.9 dependancies but doesn't install gradle 1.9 properly. So I thought I'd download the full installer with gradle 1.9 but the download link gives me the version I started with. I know. I should have known better than to update but given the issues I thought it might actually contain a fix.
Edit3: Problem solved. I have a full answer typed up ready to post but SO won't let me post it until tomorrow.
All builds are signed, even debug ones (which are signed with a debug key). It's just a matter of setting it up to sign your release builds with the correct key. You can set up a signing config via the Project Structure dialog, or you can edit the build.gradle file by hand, following the instructions in the Gradle Plugin User Guide
Once your build file is set up, you can either generate the release APK from the command line with the command
./gradlew assembleRelease
on Linux or Mac, or on Windows:
gradlew.bat assembleRelease
or in the GUI, you can generate the release build by choosing it from the Build Variants view:
building the APK, and signing it using the wizard.
I have solved the problem
Part 1 : k3v1n4ud3's link did help a lot to coalesce the information. Thank you for that.
Here is my entire build.gradle located under the project folder:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
signingConfigs {
debug {
storeFile file("debug.keystore")
}
release {
storeFile file("D:\\AndroidStudioProjects\\KeyStore\\Keystore_password1.jks")
storePassword "password"
keyAlias "MyAppName"
keyPassword "password"
}
}
productFlavors {
free {
packageName "com.mypackage.myappname"
}
paid {
packageName "com.mypackage.myappname"
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
debuggable false
zipAlign true
}
/*
alpha {
packageNameSuffix ".alpha"
}
beta {
packageNameSuffix ".beta"
}*/
}
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
android.applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
switch (variant.name) {
case "FreeRelease":
variant.mergeResources.doFirst {
android.sourceSets.debug.setRoot("src/free")
}
break;
case "PaidDebug":
variant.mergeResources.doFirst {
android.sourceSets.debug.setRoot("src/paid")
}
break;
}
}
else if (variant.buildType.name == "debug") {
switch (variant.name) {
case "FreeDebug":
variant.mergeResources.doFirst {
android.sourceSets.debug.setRoot("src/debug/free")
}
break;
case "PaidDebug":
variant.mergeResources.doFirst {
android.sourceSets.debug.setRoot("src/debug/paid")
}
break;
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Part 2: I used the keystore created when I initially used the Build->Generate Signed APK... wizard. Pay attention to the keyalias used. After half a day of banging my head against the wall i had forgotten what I'd typed :-)
Part 3: This thread helped me set up the source folders and understand the flavors. Folder naming convention for gradle build variants
Part 4: With just one AndroidManifest.xml I couldn't use the suffixes on the package names. With suffixes it was rejected when uploading to the device. That becomes a problem when pretty much every example of build.gradle includes suffixes.
Part 5: Use View->Tool Windows->BuildVariants to bring up the build variants. The second column is actually a drop down. Select what you want to build here otherwise it's just going to keep building the debug version. (Why on earth it's not under the build menu or the run/debug configurations is a mystery???)
Part 6: The future... I have to try and work out the flavors and how to set them up as I would eventually like to deploy a free and a paid version off the same code base. I will start signing the debug versions with my own key as well.
It is possible to take any existing Android Studio gradle project and build/sign it from the command line without editing any files. This makes it very nice for storing your project in version control while keeping your keys and passwords separate and not in your build.gradle file:
./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD
If you are using different gradle build version rather than in which you developed your keystore file, at that time it may affect.
I also faced this problem in my project i do following changes:
set classpath
from classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
to
classpath 'com.android.tools.build:gradle:2.1.2'

Installation failed with Android Studio, APK not signed

Recently change to Android Studio from Eclipse and I have also changed the JDK from java-open-jdk to jdk1.7.0_45.
Now I'm trying to run my first app and I get this message:
Installation failed since the APK was either not signed, or signed incorrectly.
If this is a Gradle-based project, then make sure the signing configuration
is specified in the Gradle build script
Edit:
When I'm running from Android Studio I get the error displayed above. When I'm running it from the command line I don't get an error (well the app is running and I get an error but nothing to do with gradle).
I got the code from here
You can check build.gradle here at google repo
UPDATE 2:
I added this code
signingConfigs {
release {
storeFile file("john.keystore")
storePassword "john"
keyAlias "johnkeystore"
keyPassword "john"
}
}
just above the buildTypes code block in the build.gradle file.
File john.keystore is on the root of my Project. I'm running gradlew assembleRelease and I'm getting a xxx-release-unsigned.apk.
If you indeed runing build with gradle you need to configure signingConfigs. Android can configure your debug signingConfig automatically. You can make release signingConfig in a next manner:
android {
signingConfigs {
release {
storeFile file('android.keystore')
storePassword "pwd"
keyAlias "alias"
keyPassword "pwd"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Check manual on this topic here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Signing-Configurations
If you still have issues, please update question with your build.gradle. Most likely issue is laying here. I'm using JDK 1.7 and gradle builds are working fine.
I had the same problem, i went to Build->Clean Project and re-execute the project and it worked.
I have been struggling for a while with Android Studio esp. gradle and build variants.
I have change this from the build types as defined:
debug
release
As I ran into the same problem (while developing and running tests), I went to Build -> Rebuild Project and then re-launched the emulator. That worked for me.
None of the answers worked for me, even after uninstalling app from phone, I could not deploy it. What worked was installing the app o a different device, and then when I tried to deploy it on the previous device, it miracleously worked.
If your goal is not to create a custom build for your application you might want to clean all the data about it from your test device, in case you are using emulator just wipe all the data from device. Go to -> Tools -> Android -> AVD Manager -> [Device you wanna wipe] (In actions tab) -> Wipe Data.
In case of actual device just uninstall the app and all related data.
Reason is that unsigned APK has a signature, so device sees you're trying to install something with the same package name that was generated not here.
Hope this saves you some time.
In case your device has multiple users, before installing signed APK, check if the same app is not installed for other users. If it is there remove it.
For me this was the root cause of rejecting installation of signed APK.
Just to Build -> Rebuild Project and then re-launched the emulator. That worked for me.

Generating a Pro Guard configuration file with Android Studio

I am using Android Studio since 0.1.0 ... I just learned yesterday that Pro Guard seems to be integrated in newly created projects. Unfortunately this is not true for my project (which was a former Eclipse project). I didn't know of Pro Guard until I started working with Android Studio. And now I am looking for examples on how to use Pro Guard with Android Studio. Unfortunately the Android Dev documentation is only mentioning situations where the configuration file is already created. Is there a possibility to get Android Studio to create a configuration file to an already existing project?
I was also not able to do it through Android Studio. However, this worked for me.
Add the following sections to the "android" section of your build.gradle file, filling in your own implementation details where appropriate.
android {
...
signingConfigs {
releaseConfig {
storeFile file("/dir/to/your.keystore")
storePassword "xxx"
keyAlias "yyy"
keyPassword "xxx"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../your_proguard_file.txt'
signingConfig signingConfigs.releaseConfig
}
}
}
In your project folder, run ./gradlew clean and ./gradlew assembleRelease
You can copy the default Proguard configuration file to your project.
sdk-location/tools/proguard/examples/android.pro — copy and paste it as proguard.cfg in your project. Then choose it when AS asks for the config file path.
The complete ProGuard configuration that is generated by your rules (.pro) file can be saved by appending the -printconfiguration command to your existing rules. i.e.
-printconfiguration 'C:\Example\File\Path\proguard-configuration.txt'

Categories

Resources