android clicking debug chooses release variant - android-studio

In Android Studio, when I click the "debug" icon in the tool bar, gradle is appearing to try to make a release build.
First, it shows me the "edit configuration" popup. At the bottom, it has a message "the apk for your currently selected variant (app-release-unsigned.apk) is not signed. Please specify a signing configuration for this variant (release).
Why is it trying to use "release" when I click "debug"? Obviously I changed something, I wish I knew what...
Here's my app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
compileOptions.encoding = 'UTF-8'
defaultConfig {
applicationId "com.perinote.camera"
minSdkVersion 15
targetSdkVersion 24
renderscriptTargetApi 20
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:24.0.0'
testCompile 'junit:junit:4.12'
}

Solved by deleting the .idea directory. After it was regenerated, my builds were correctly produced.
I also completely removed and reinstalled Android Studio and the SDK. However, the debug build was still messed up after that.

Related

Build error when trying to Run basic activity

I'm on day 1 of learning Android Studio / Kotlin and working my way through the (official?) tutorials.
Having added some basic views to an empty layout and resolved a couple of "coding practice" warnings, when I try to run the app on a USB connected tablet, I get a build failed message.
(I haven't got as far as any Kotlin coding yet.)
I'm completely out of my depth at this stage and can't find a solution that isn't beyond my level of understanding.
The errors are ...
Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
If there's any other information worth sharing, I'm afraid I don't know what it is at the moment.
ANy suggestions on what I need to do to or investigate to resolve the build fail?
First build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Second build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.test04"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Try these steps.
Update your Kotlin version from "1.5.10" to the latest "1.5.31" in your first build.gradle file. Also update the Kotlin plugin: File -> Settings -> Languages and Frameworks -> Kotlin and if there's a new version there will be an Install button to click. Then restart Android Studio and run your project to see if it will work.
If that doesn't work, you can manually add the missing reflection library to your project. I don't see in your dependencies anything that uses reflection, but maybe I'm missing something. So, add this line into the dependencies section of your second build.gradle file:
implementation "org.jetbrains.kotlin:kotlin-reflect"
Then click the "Sync Project with Gradle Files" button near the right end of the toolbar (elephant with blue arrow icon), and try running your project again.
The Android Build Tools you're using is also out of date. I'm not sure it could be related, but you can update that as well in the first build.gradle file. Change the 4.2.2 to 7.0.3 and click the Gradle sync button again. Android Studio might complain that you need to update your Gradle version, so click yes if it offers to update it for you.

How to change build tools version in Android Studio 3.0.1?

I just upgraded my Android studio from 2.3 to 3.0.1. But I get this error message(I have already installed API 27 ) and don't know how to fix it, because I couldn't find the the build tools version in new version of android studio!
Error:Failed to find Build Tools revision 26.0.2 Install Build Tools 26.0.2 and sync project
The gradle files are changed, also the project structure has only one tab!
Edit:
this is the content of `app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.m.finalocr"
minSdkVersion 21
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 fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
As you can see, there is no buildToolsVersion in it. So, why my android studio looks for this specific version(26) of that when I have the 27 version installed on my computer? Also, where can I see the buildToolsVersion "26.0.2" and change it tobuildToolsVersion "27.0.3" ` ?
Your project is looking for Build Tools version 26.0.2, but you haven't yet downloaded and installed it on your computer.
To download it, go to Tools > Android > SDK Manager, then click on the "SDK Tools" tab at the top of the new window. Then select the "Show Package Details" checkbox in the lower right-hand corner. Finally, scroll down to where you see 26.0.2, check the checkbox next to it, and click "OK" to begin the install process.
If you want to change the Build Tools version in your project, that is specified in project's build.gradle file (in the 'app' module). Open the file and either add or update the Build Tools version you want to use by adding/updating the following property in the 'android' section:
android {
buildToolsVersion "27.0.3"
...
}

New Android Studio + New project - Failed to resolve

I am trying to make my first Android App.
Downloaded and installed the Android Studio, and followed the tutorial to start a new simple "Hello world" app, just to get started, and see that everything works.
But it does not.
I have not written one single line of code myself, so the source is completely generated by Android Studio itself.
I get this error:
Failed to resolve: com.android.support:appcompat-v7:25.+
and
Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
When creating the project, I choose API level 15.
In the SDK manager, I have both API level 15 and 25 installed ( I think 25 was default installed, and I have installed API 15 or vice versa).
I have googled a lot, and tried different SDK's, but always the same error. No matter what versions I try to use, it fails with the same message.
Why doesn't the very first tutorial work?
I am a bit confused, if it is so difficult to make the first "Hello world" app :0)
Screenshor of error
Thanks in advance !
Go to File -> Settings -> Build,Execution,Deployment -> Build Tools -> Gradle and then uncheck Offline and then resync the project and rebuild even if all of the above doesn't work try reinstalling the whole setup
#Rahul
Here is the Screenshot of my Tools installed.
Google Repository installed too
Screenshot of Tools
#Rahul Kumar
My build.gradle below.
Project is created using API 15 as minimum.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "dk.surlution.app3"
minSdkVersion 15
targetSdkVersion 25
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(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:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
testCompile 'junit:junit:4.12'
}

Gradle cannot find symbol class in Android Studio project

Gradle has trouble resolving a dependency in an Android Studio project. I have a library that has a dependency to a java module called "common". I have the dependency speficied in the buld.gradle (see below), however, I still get "cannot find symbol MyClass" when building. How can I fix this?
The line in error is the import that references the package in "common".
Building works fine with maven, but not with gradle.
This is the build.gradle of my lib.
apply plugin: 'com.android.library'
android {
compileSdkVersion 17
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':common')
}

Why must I Run my Android App to generate an APK file

I am using Android Studio 1.1.0 to build an APK for internal distribution in my company using AirWatch.
My understanding of how to build an APK is to go to the "Build==>Make Project". However, when I do that AS does not generate an APK. However, if I go to "Run==>Run App" then I do get an APK.
I fear I have something misconfigured in AS, as this is my first project.
Bryan
There are two.
Here is the first.
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'XXXXXXXXXXXXXXX'
keyPassword 'password'
storeFile file('PATH')
storePassword 'XXXXXX'
}
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.ACME.application"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug{
debuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/commons-lang-2.3.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile files('src/main/assets/library-1.0.10.jar')
}
Here is the second.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Seems like you are getting correct behavior from Android Studio.
You are correct that to build an APK, you can go to the "Build==>Make Project". When you "build" the project, you are just creating the APK, not installing it on any device or emulator. So you won't see your app 'running' anywhere after this step. Selecting this item in the GUI is the same as running the command line gradle build.
The APK is placed in this directory:
<Your root project folder>/<app name>/build/outputs/apk
You can then install this APK on a device using the command line, or by dragging and dropping the file onto an emulator.
When you go to "Run==>Run App" then you also get an APK. But you get even more! This apk is not only built, it is installed onto your connected device / emulator automatically for you. Selecting this item in the GUI is the same as running the two commands gradle build and adb install.

Resources