How to FTP a file from an Android Gradle build? - android

I'm trying to FTP the signed APK after a Gradle build. I've already added the new build config that will sign the APK, but I'm stuck trying to figure out how to invoke an FTP task.
I found an official looking sample at section 59.6, however it complains that it cannot resolve dependency org.apache.ant:ant-commons-net:1.8.4. So apparently I'm missing something obvious here, like where to put a given jar file or reference it, although I thought maven would handle this sort of thing?
For reference, here is the linked sample which fails with a message about the dependency:
configurations {
ftpAntTask
}
dependencies {
ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
module("commons-net:commons-net:1.4.1") {
dependencies "oro:oro:2.0.8:jar"
}
}
}
task ftp << {
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: "ftp.apache.org", userid: "anonymous", password: "me#myorg.com") {
fileset(dir: "htdocs/manual")
}
}
}
This fails with the message:
> Could not find org.apache.ant:ant-commons-net:1.8.4.
Here is my complete gradle.build file, with some sensitive information removed:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
signingConfigs {
signed {
storeFile file("(removed)")
storePassword "(removed)"
keyAlias "(removed)"
keyPassword "(removed)"
}
}
buildTypes {
signed {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.signed
}
}
}
configurations {
ftpAntTask
}
dependencies {
ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
module("commons-net:commons-net:1.4.1") {
dependencies "oro:oro:2.0.8:jar"
}
}
}
task ftp << {
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
ftp(server: "(removed)", userid: "(removed)", password: "(removed)", remoteDir: "(removed)") {
fileset(dir: "(removed)") {
include(name: "(removed)")
}
}
}
}

You havn't declared a repository that can be used to resolve the declared artifacts. Try adding the following snippet to your build.gradle file:
repositories{
mavenCentral()
}
cheers,
René

You can also use the native ant get task which supports FTP, works with no outside dependencies:
ant {
get(src: "ftp://<hostname>/remote/path/to/file.jar", dest: "/local/path/to/file", username: 'anonymous', password: 'anonymous')
}

Related

Cannot find local aar built through Flutter Module

I am trying to add the flutter module as aar dependency on my Android Project. Here is the guide
https://flutter.dev/docs/development/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency
I am able to generate the local AAR and I can see these steps to be done:
1. Open <host>/app/build.gradle
2. Ensure you have the repositories configured, otherwise add them:
repositories {
maven {
url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
3. Make the host app depend on the Flutter module:
dependencies {
debugImplementation 'com.example.animation_module:flutter_debug:1.0
profileImplementation 'com.example.animation_module:flutter_profile:1.0
releaseImplementation 'com.example.animation_module:flutter_release:1.0
}
4. Add the `profile` build type:
android {
buildTypes {
profile {
initWith debug
}
}
}
In my Android project, I have app module and library module. I want to include this aar in my library module, here is my library module build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
profile {
initWith debug
}
}
}
dependencies {
debugImplementation 'com.example.animation_module:flutter_debug:1.0'
profileImplementation 'com.example.animation_module:flutter_profile:1.0'
releaseImplementation 'com.example.animation_module:flutter_release:1.0'
}
repositories {
maven {
url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
I have also added mavenLocal() at my project's build.gradle in repository. (Tried with and without it) But dependencies are not resolved.
I get an error:
Could not find com.example.animation_module:flutter_debug:1.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
- https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
- https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
- https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
Required by:
project :app > project :animation_flutter_sdk
I know dependency is not present on the remote at https://dl.google.com but it is present in my local and gradle should pick it up from my local. Please help me how to build this project.
I have a project with several library modules and an app module. I faced the same issue as I wanted to start the flutter module from one of my library modules.
I solved it by adding
repositories {
maven {
url '../path/to_your/flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
in both app module and library module build.gradle
I didn't need mavenLocal().
I also needed to add
profile {
initWith debug
}
in each modules build.gradle.
This is now how my app module and library module build.gradle looks like:
App module build.gradle:
plugins {
id 'com.android.application'
}
repositories {
maven {
url '../core/webshop/flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
android {
compileSdkVersion toolVersions.compileSdk
defaultConfig {
...
}
signingConfigs {
release {
...
}
}
buildTypes {
release {
...
}
profile {
initWith debug
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Project modules
implementation project('your_lib_module1')
implementation project('your_lib_module2')
...
}
Library module build.gradle, where you want to add flutter module:
apply plugin: 'com.android.library'
repositories {
maven {
url './flutter_repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
android {
compileSdkVersion toolVersions.compileSdk
defaultConfig {
...
}
buildTypes {
release {
...
}
profile {
initWith debug
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Project modules
implementation project('your_lib_module3')
// flutter
debugImplementation 'com.example.animation_module:flutter_debug:1.0'
profileImplementation 'com.example.animation_module:flutter_profile:1.0'
releaseImplementation 'com.example.animation_module:flutter_release:1.0'
...
}
I have the same issue and solve it adding in repositories of settings.gradle inside of dependencyResolutionManagement
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
maven {
url '/yourpath/your_flutter_module/build/host/outputs/repo'
}
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
}
I have the same problem, it is solved by setting the configurations
android {
buildTypes {
release {
....
}
profile {
....
}
debug {
....
}
}
}
configurations {
// Initializes a placeholder for the profileImplementation dependency configuration
profileImplementation {}
}
dependencies {
debugImplementation xxx
// Then it can work
profileImplementation xxx
releaseImplementation xxx
}
Picking a specific build type in a dependency

How to download sources from specific dependency in Gradle

I am trying to know how to get gradle to download the source of a given dependency. All that I've searched has not work. I've seen the property DownloadSources. But I do not know where to write it in my Android gradle file.
I've tried to write it in different locations, inside dependencies {}, android { }, defaultConfig {}. But no luck. In a regular gradle file like this, where have I to use downloadsources?:
Project file
sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//..
}
}
allprojects {
repositories {
// ..
}
}
Module file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
// ...
}
buildTypes {
release {
//....
}
}
}
dependencies {
// ...
compile 'it.neokree:MaterialNavigationDrawer:latest.release'
}
Sorry if its a dummy question, but I can not find a solution.
You can set it for all dependencies. For idea use:
idea {
module {
downloadSources = true
}
}
For Eclipse:
eclipse {
classpath {
downloadSources=true
}
}

Having troubles generating Android gradle signed and zipaligned apk

I am having trouble getting a signed zipaligned gradle file built in my Android app. I am using intellij 13.1.4. The error I am receiving is Error:(34, 0) Could not find property 'configstd' on BuildTypeDsl_Decorated{name=release, debuggable=false, jniDebugBuild=false, renderscriptDebugBuild=false, renderscriptOptimLevel=3, packageNameSuffix=null, versionNameSuffix=null, runProguard=false, zipAlign=true, signingConfig=null}.
Here is my build.gradle:
` buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
signingConfigs {
configstd {
keyAlias 'myalias'
keyPassword 'mykeypassword'
storeFile file('mykeyfile.jks')
storePassword 'mystorepassword'
}
}
buildTypes {
release {
debuggable false
zipAlign true
signingConfig configstd
}
debug {
debuggable true
zipAlign false
signingConfig configstd
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.android.support:appcompat-v7:19.+'
}
`
Here is what I discovered to be the problem. I originally had used the intellij's Project Structure->Facets->Android-Gradle to enter the parameters for the build.gradle file. Apparently, when it created the code to insert into the file it left off "signingConfigs" from the name of the object configstd. So in other words the line should read as follows:
signingConfig signingConfigs.configstd

Gradle can't find dependency

I have problem with gradle in Android Studio 0.5.2.
It's shown below:
Could not find com.android.support:support-v4:19.0.0.
Required by:
org.codepond:wizardroid:1.2.0
Please install the Android Support Repository from the Android SDK Manager.
I Also Installed Android Support Repository.
My build.gradle looks like this:
apply plugin: 'android-library'
apply plugin: 'android-maven'
apply plugin: 'signing'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode project.ext.versionCode
versionName version
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
boolean hasCredentials = hasProperty('sonatypeUsername') && hasProperty('sonatypeUsername')
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
if (hasCredentials) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
if (hasCredentials) {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
}
pom.project {
name 'WizarDroid'
description 'Lightweight Android library for creating step by step wizards'
url 'http://wizardroid.codepond.org'
scm {
url 'http://www.github.com/nimrodda/wizardroid'
connection 'scm:git://github.com/Nimrodda/WizarDroid.git'
developerConnection 'scm:git://github.com/Nimrodda/WizarDroid.git'
}
licenses {
license {
name 'The MIT License (MIT)'
url 'https://raw.github.com/Nimrodda/WizarDroid/master/license'
distribution 'repo'
}
}
developers {
developer {
id 'nimrodda'
name 'Nimrod Dayan'
email 'feedback#codepond.org'
}
}
organization {
name 'CodePond.org'
url 'http://www.codepond.org'
}
issueManagement {
system 'GitHub Issues'
url 'https://github.com/nimrodda/wizardroid/issues'
}
parent {
groupId 'org.sonatype.oss'
artifactId 'oss-parent'
version 7
}
}
}
}
}
You should change build.gradle to
dependencies {
compile 'com.android.support:support-v4:19.1.+'
}

Android gradle file to remove unused resources

I would like to remove unused resources from my final release apk file created. I am able to configure proguard but its limited to Java files only. I would like to remove unused layouts, strings, pngs etc Any ideas?
I read android link can help; got the script here: http://yltechblog.blogspot.in/2012/06/remove-unused-resource-from-android.html but i donnot know how to integrate it with gradle.
Similarly: https://code.google.com/p/android-unused-resources/; claims to help; but i am unable to figure out how to integrate it with gradle.
My gradle file is as follows
// COMMANDS::
// gradle --build-file adt_build.gradle clean build
// adb -e install -r build/apk/rpsl-debug-unaligned.apk
buildscript {
repositories {
mavenLocal()
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
apply plugin: 'eclipse'
def artifactoryurl='http://10.10.8.10:8081/artifactory'
repositories {
mavenLocal()
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
maven {url "$artifactoryurl/jfrog-libs"}
maven {url "$artifactoryurl/plugins-release"}
maven {url "$artifactoryurl/libs-local"}
}
dependencies {
compile 'com.google.code.gson:gson:2.2.4' , 'android:support:v4', 'wavecrest.mobile.libraries:libraries:2'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
signingConfigs {
debugconfig {
storeFile file("../configs/keystore.jks")
storePassword "asdf"
keyAlias "rpsl"
keyPassword "asdf"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
signingConfig signingConfigs.debugconfig
zipAlign true
runProguard true
proguardFile file('configs/proguard-android.txt')
}
release {
signingConfig signingConfigs.debugconfig
zipAlign true
runProguard true
proguardFile 'configs/proguard-android-optimize.txt'
}
}
defaultConfig {
versionCode 1
}
sourceSets {
main {
manifest{
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res.srcDirs = ['res']
}
instrumentTest.setRoot('tests')
}
}
Lint support is not complete yet with the android gradle plugin. It is scheduled for next release.
From there, you might be able to use the lint results. In gradle to execute a script do something like 'script'.execute()

Categories

Resources