Generating signed apk android studio - android-studio

Can anyone tell me how to generate signed apk of next version of any app in android studio??? In which file do I have to update? I am not familier with android studio
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.app"
minSdkVersion 11
targetSdkVersion 21
}

add the lines versionCode and versionName below the line targetSdkVersion 21
For example if your app version is 1.0 your gradle file will be
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.app"
minSdkVersion 11
targetSdkVersion 21
versionCode 10
versionName "1.0"
}
and if your app version is 2.0.3 your gradle file will be
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.app"
minSdkVersion 11
targetSdkVersion 21
versionCode 203
versionName "2.0.3"
}

Scroll to the left of the screen in Android Studio and click on build variants.
Select "release".
Scroll to the top of the screen and select "Build".
Select "Generate Signed Bundle/APK".
Create a new keystore and SAVE YOUR PASSWORD
Finally, select "Generate" or "Build" and after a bit a file will appear called something like "release.apk".
Here is the google documentation: Here

Related

Could not find method namespace() for arguments [com.android.mylib] on extension 'android' of type com.android.build.gradle.LibraryExtension

I am trying to create a library in android studio by following this official documentation. But in this particular project, I am facing this issue. if I create new project and create new lib I don't face any issue.
My Lib Gradle
plugins {
id 'com.android.library'
}
android {
namespace 'com.android.mylib'
compileSdkVersion 33
defaultConfig {
minSdkVersion 26
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
App Gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 33
buildToolsVersion "30.0.2"
testBuildType "beta"
defaultConfig {
applicationId "com.app.etc"
minSdkVersion 23
targetSdkVersion 33
versionCode 327
I have searched some questions, but according to those answers, everything seems correct. i have invalidated cache and restarted the android studio as well.

android studio : minSdkVersion 22 error

I am a complete beginner in android studio and I was having trouble with setting minSdkVersion to 22 for android wear. The problem is caused because of library dependency since it requires the minSdkVersion to be 23 minimum. I looked up in the web and didn't seem to find a solution of how to set the minSdkVersion to 22.
The cod is given below
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "enterprise.supti.myapplication"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.android.support:wearable:2.3.0'
implementation 'com.google.android.gms:play-services-wearable:15.0.1'
implementation 'com.android.support:percent:28.0.0-rc01'
implementation 'com.android.support:support-v4:28.0.0-rc01'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
implementation 'com.android.support:wear:28.0.0-rc01'
compileOnly 'com.google.android.wearable:wearable:2.3.0'
implementation 'com.android.support:support-annotations:28.0.0-rc01'
}

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.>Compilation failed; see the compiler error output for details

apply plugin:'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
multiDexEnabled true
applicationId "com.tubbs.citychurchob"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
android.support.test.runner.AndroidJUnitRunner
buildTypes{
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir:'libs', include:['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.firebaseui:firebase-ui:0.4.2'
compile 'com.google.firebase:firebase-database:10.0.1'
}
How to fix this error
Pls ans me.....
I'm using Android studio 2.3.1

Could not find method ndk() for arguments

I'm following Create Hello-JNI With Android Studio.
MAC OX 10.11.5
Android Studio 2.2 stable
java version: 1.7.0_79
gradle-2.14.1
Here's my app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.chenql.helloandroidjni"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
ndk {
moduleName "hello-android-jni"
}
}
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:23.3.0'
compile 'com.android.support:design:23.3.0'
testCompile 'junit:junit:4.12'
}
Here's the error:
The Error Message
Error:(20, 0) Could not find method ndk() for arguments [build_13jh6qtzl4f08f8c1of3mvsys$_run_closure1$_closure5#5b127949] on project ':app' of type org.gradle.api.Project.
Open File
It turns out that this code
ndk {
moduleName "hello-android-jni"
}
should be placed under "defaultConfig" block:
defaultConfig {
applicationId "com.chenql.helloandroidjni"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "hello-android-jni"
}
}
instaed of after "buildTypes" block.
Upgrading to a newer version of the Gradle plugin solves
You just add the following code in android/app/build.gradle
android {
ndkVersion rootProject.ext.ndkVersion //<-- add line
compileSdkVersion rootProject.ext.compileSdkVersion
And in android/build.gradle
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 30
ndkVersion = "22.1.7171670 || {{use your ndk_version}}" //<-- add line
Thats it. Rebuild the app
Comment or delete ndkVersion 'version number' at build.gradle

Test running failed: Permission Denial: starting instrumentation ComponentInfo

Test running failed:
Permission Denial: starting instrumentation ComponentInfo{com.xxx.taskmanager.warehouse.tests/android.test.InstrumentationTestRunner} from pid=766, uid=766 not allowed because package com.xxx.taskmanager.warehouse.tests does not have a signature matching the target com.xxx.taskmanager.warehouse
Empty test suite.
This is my app.gradle file
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
signingConfigs {
release
{
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('../keystore.jks')
storePassword 'xxx'
}
}
compileSdkVersion 16
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.0"
testApplicationId "com.xxx.taskmanager.warehouse.tests"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'LICENSE'
exclude 'NOTICE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"FLO_HANDHELD_V${variant.versionName}.apk"
)
}
}
variantFilter { variant ->
if(variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
productFlavors {
production_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2B"
}
stage_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2B"
}
production_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2C"
}
stage_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2C"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files ('libs/android-support-v7-appcompat.jar')
compile files('libs/android-support-v4.jar')
compile project(':taskmanagerlib')
compile files('libs/DataCollection.jar')
androidTestCompile fileTree(dir: 'libs', include: 'robotium-solo-5.3.0.jar')
}
task copyTask(type: Copy) {
from 'build/outputs/apk'
into 'apks'
exclude '**/*-unaligned.apk'
}
task deleteApk(type: org.gradle.api.tasks.Delete){
// delete 'apks'
}
task appBuild(dependsOn: ['deleteApk','clean', 'assembleRelease', 'copyTask']){
assembleRelease.mustRunAfter deleteApk
clean.mustRunAfter deleteApk
copyTask.mustRunAfter assembleRelease
}
I think this error is happening because I have not declared the signingConfigs for test package. If so , how do I declare it. ?
Please help!!
I have solved the issue. Answering it so that it can be useful for someone else.
Solution is for Android Studio :
For the tests to run , the build variant should be debug. Build Variants window is present in the left side of the android studio, if not activated then activate it by click on Build variants tab present on the left side of the android studio.
You either have to change your build variant to debug, or add a testBuildType to your android tag inside your build.gradle file. Like this:
android {
...
testBuildType "release"
}
Clean Your Project.
Uninstall app if already install.
Now Run your project.
It's Completely Working for me.
Had the same problem even with Android Studio 3.x years later. Previous answers did not work for me.
Only cure was to explicitly add the permissions to the test app on the phone.
It worked for me when changed Startapp code to use apk file instead of installed App.
i.e. from :
From :
return GetApp().InstalledApp(Settings.AUTPackageName).EnableLocalScreenshots().ConnectToApp();
To:
return GetApp().ApkFile(Settings.AUTPath).EnableLocalScreenshots().ConnectToApp();

Resources