How to Zip a folder using Android Gradle? - android

I am trying to zip an android source using gradle but my gradle task not doing anything. After completing the gradle sync, nothing happening, my source is not zipping.
I followed this but didn't work.
My Gradle :
apply plugin: 'com.android.application'
task myZip(type: Zip) {
from 'src/main/assets/'
include '*/*'
archiveName 'test.zip'
destinationDir(file('src/main/'))
println "Zipping Continues... "
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "test.sample.com.myapplication"
minSdkVersion 15
targetSdkVersion 26
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'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
This is my gradle scripts and please suggest me some solution.

I hit the same issue when I wanted to zip the JNI libs with symbols before publishing them to a private maven feed. It took me some time to figure out the steps as I am not familiar with Gradle. Basically, I solved it by adding an extra step to run the myZip task in the build pipeline:
./gradlew build
./gradlew myZip # extra step to run the myZip task
./gradlew publish
Here is part of my build.gradle as for reference:
apply plugin: 'maven-publish'
task myZip(type: Zip) {
archiveName "symbols.zip"
from "$buildDir/intermediates/transforms/mergeJniLibs"
destinationDir file("$buildDir/outputs/sym")
doFirst {
println "Run myZip task to create symbols.zip"
}
}
publishing {
publications {
symbolsPublication(MavenPublication) {
... ...
artifact file("$buildDir/outputs/sym/symbols.zip")
}
}
}
... ...

Related

Build Command Failed for CMake

I updated android studio and now I am getting the following error while trying to run the app.
Build command failed.
Error while executing process
C:\Users\bhaskar\AppData\Local\Android\sdk\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build C:\Users\bhaskar\Desktop\New Projects\otv
2\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target baseUrl}
Unknown argument Projects\otv
Unknown argument 2\app\.externalNativeBuild\cmake\debug\armeabi-v7a
Usage: cmake --build <dir> [options] [-- [native-options]]
I have tried the link but didn't work for me.
Android Studio CMake Error: Build Command failed
My build.gradle file is:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.osolutions.otv"
minSdkVersion 16
targetSdkVersion 28
versionCode 9
versionName "1.1.1"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
ndk {
abiFilters "armeabi-v7a", "x86"
}
externalNativeBuild {
cmake {
version "3.10.2"
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation files('libs/YouTubeAndroidPlayerApi.jar')
// retrofit, gson
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
}
I have tried clean and rebuild the project, Invalidate cache and restart, tried steps in the link that I have shared none of it seems to be working for me. Any help would be appreciated.
I solved it by using older version of cmake. I had two versions folder inside path
C:\Users\bhaskar\AppData\Local\Android\sdk\cmake
3.6.41111459 and 3.10.2.4988404. I deleted the 3.10.... folder and run the project and it worked fine.

Android app build error. Unable to merge dex [duplicate]

This question already has answers here:
Unable to merge dex error [duplicate]
(2 answers)
Closed 5 years ago.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I am using version 3.0.1 of Android Studio.
I also tried 'clean project' and 'rebuild project'.
*project build gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
*module build gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
ext {
grpcVersion = '1.4.0'
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.backkom.speechtest"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.3.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
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'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
// gRPC
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.3.1'
compile group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '0.1.13'
// OAuth2 for Google API
compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}
compile 'com.android.support:multidex:1.0.2'
}
When I do a rebuild project, I get an error like below.
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [C:\Users\backkom\AndroidStudioProjects\SpeechTest\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\backkom.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java\3.3.1\e8964a2667e55d11a4505b329a4c34247663920b\protobuf-java-3.3.1.jar(;;;;;;**.class)] (Duplicate zip entry [protobuf-java-3.3.1.jar:com/google/protobuf/ExperimentalApi.class]))
From your error log it seems like your directory backkom is not available for android studio . so please check your directory
C:\Users\backkom
is writable or not . by doing so . go to that directory and check its permission . is it has read and write both permission or not .
As per my understanding,
Try this :
Clean Project button.
Rebuild Project button from the Build menu.
And change your local.properties with this
org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
And define gradle in this way
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 21
targetSdkVersion 26
versionCode 7
versionName "0.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
And add this multidex in your project
compile 'com.android.support:multidex:1.0.1'
and Define it in Manifest

Android Studio APK build error - Multiple dex files define Landroid/support/v4/

//Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.cpsraozan.admission"
minSdkVersion 15
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 {
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:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
}
apply plugin: 'com.google.gms.google-services'
Go to your build.gradle file and add multidexEnable true on defaultConfig.
android {
compileSdkVersion 26
defaultConfig {
targetSdkVersion ..
multiDexEnabled true //add this
}
}
For more information See this
This is kind of NOT straight forward. Most likely you might have added a new dependency or updated a dependency which is causing multiple versions of the same library being added as a dependency.
Check if Android studio is highlighting any lines for this, especially in Gradle files.
Run a dump of all dependencies Gradle is processing using the command
./gradlew -q dependencies app:dependencies
check for conflicting dependencies and fix them.
I was struggling this morning with the same error and the requirement for multiDexEnabled didn't make sense. This is only for large projects with more than 64k methods. I found this solution somewhere on SO, but couldn't find it again. So reposting the answer.

Can't Create Project in android studio

Error:failed to create directory 'D:\rw_apps\MyApplication\app\build\generated\source\r\debug\com\example\bhavin\myapplication'
Error:java.util.concurrent.ExecutionException:com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:Execution failed for task ':app:processDebugResources'.
Failed to execute aapt
I tried lots of solution from other stackoverflow answers like
clean project,
restart android studio,
change build-tools,
re-download build-tools.
Run with --stacktrace are long so I share text file please check it.
I am using android studio 3.0 beta 6.
MY gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 26
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
Set android.enableAapt2=false in your gradle.properties file

How add ViewPagerIndicator to android studio

I see this link Using ViewPagerIndicator library with Android Studio and Gradle and here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
packagingOptions {
exclude 'AndroidManifest.xml'
}
defaultConfig {
applicationId "com.example"
minSdkVersion 10
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/nineoldandroids-2.4.0.jar')
compile "com.android.support:appcompat-v7:18.0.+"
compile('com.viewpagerindicator:library:2.4.1') {
exclude module: 'support-v4'
}
}
And gradle build has successfully completed .But i can't import com.viewpagerindicator.PageIndicator
.I also check .gradle folder and viewpager folder already exist.Any ideas?
Did you add library in Android Studio by File -> Project structure... -> Libriaries (or Modules)?
Use the full file path to the location of the jar. That's worked for me every time. If you're using Android Studio make sure to 'Sync Project with Gradle Files' and rebuild as well.

Categories

Resources