I'm setting up a CI build system for an android project and am having trouble using gradle to download the artifacts from the build.
In the first step I use gradle to build an .apk and then I push it to a Nexus repository as an artifact. This works successfully and I can see my apk in my repo.
In the second step I am attempting to pull the .apk down from the repository and push it to a device farm. The .apk uploads to the repository just fine, but I can't figure out how to get gradle to download it.
Ideally, in the same build.gradle file that is used to upload the file, I'd have some sort of gradle task that would download the file from the repo and allow me to manipulate it.
So far I've tried:
Specifying the file as a dependency. I add the dependencies closure with a compile(group, name, version, classifier, apk) inside of it. When I run it, it seems that gradle can find the file, however I get this error
apk on project app resolves to an APK archive which is not supported as a compilation dependency.
I believe this is because I'm using the compile command and since I'm downloading an .apk that's not really a thing that you can do to it.
I attempted to use this library
https://github.com/michel-kraemer/gradle-download-task
but am running into issues running it on my machine because of the native .so libraries.
Does anyone know how to use gradle to download an .apk from a nexus repository?
I finally found a way to do what I wanted. In my app level build.gradle I added the following:
configurations {
drivers
}
dependencies {
drivers (group: 'com.my.groupname', name: 'myAppId', version: '0.0.123-SNAPSHOT', classifier: 'apk', ext: 'apk')
}
task copyDrivers(type: Copy) {
from configurations.drivers
into "/builds/dev/mobile-android-sync/android/app/build"
}
Note that when I uploaded my artifacts I used the following code (I think it's important because I specified a classifier):
artifacts {
archives(apk) {
type = "apk"
classifier = 'apk'
}
archives(testApk) {
type = "apk"
classifier = 'testapk'
}
}
Related
Requirement:
I have two library projects example, projectCoreModules, and projectCoreValidation.
Project A referring these two aar library projects and it's working fine.
current requirement, new project B also wants to refer this two aar library.
So, I created a separate repo for coreModules and CoreValidation projects in Azure DevOps.
Whenever PR is raised, the pipeline build will be triggered and it will publish the aar files.
I know, we can refer to the azure artifact feeds, in our android apps using the below code in Gradle.
api (group: 'Tst', name: 'TestingPackage', version: '3.1.0', ext: 'jar')
Same like this way, Is it possible to refer to the published aar files to projectA and projectB. So that I can reduce the code.
Even though I have tried with the universal package, through the build pipeline I can able to publish as a universal package. But, I was unable to refer those published to ProjectA and ProjectB. so that Gradle build of these two projects gets to succeed.
We are using similar in our project. However instead of using ext: "jar", we don't use any ext and it is working. Try this:
api (group: 'Tst', name: 'TestingPackage', version: '3.1.0')
I suppose you have already setup your repository source at the project level build.gradle file. We have setup like so
allprojects {
repositories {
google()
mavenCentral()
maven {
url project.ARTIFACT_URL
name project.FEED_NAME
credentials {
username project.PROJECT_NAME_ON_AZURE
password System.getenv("SYSTEM_ACCESSTOKEN") != null ? System.getenv("SYSTEM_ACCESSTOKEN") : project.MAVEN_ACCESS_TOKEN
}
}
}
}
I am trying to download a dependancy library mylibrary.aar from my gitlab repository via gradle. I understand that we dont have any closures/methods in gradle to directly get files from a http url.
Therefore am using ant's getmethod to download the library from gitlab.
Here is the code am using in my gradle file to get the library.
task downloadlib {
ant.get(src: 'https://my-git-link/mylibrary.aar', dest: 'libs', verbose: 'on')
}
dependencies {
compile(name: 'mylibrary', ext: 'aar')
}
Problem :
The files which I download via the ant's get method seems to be corrupted/does not go through the download process properly. Not sure what goes wrong. The library does not get compiled and the dependencies cannot be resolved. When I try to extract the aar it again extracts to cgpz file in my mac.I havent tried in windows though.
However, if I manually download the same aar file and reference it in the libs folder it works absolutely fine.
Any idea why does this happen?
Is there any other way to download a aar file from a gitlab server apart from ant.get?
Any help on this is much appreciated.
Note : I cannot use a locally built dependancy as all my libraries are on different repo and the project requirement mandates the same.Also, the code cannot be posted in github and thats the reason I did not choose jitpack
The same problem occurs for jar files as well.
I dont think I have a direct solution for the problem as gradle does not have an api for this. Instead what I did was, created my own maven repository using jfrog's artifactory and hosted the libraries there so that all the developers can refer to the libraries from the internal artifactory.
The artifactory OSS version can be downloaded from here
I chose artifactory because it was much simpler and had a great UI. Most of all it did not require setting up a separate github repository for this purpose as the code cannot be shared outside the organization.
After setting up, your libraries can be accessed as below.
http://localhost:8081/artifactory.
A brief description of setting up an artifactory is provided here
After the libraries are hosted in your artifactory which can be located anywhere in your network, u or any other developer in your organization may access your libraries using the maven dependency manager in android.
I hope this helps.
Do it like this example:
implementation 'com.quickblox:quickblox-android-sdk-core:2.5.2#aar'
implementation('com.quickblox:quickblox-android-sdk-chat:2.5.2#aar') {
transitive = true
}
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
I have downloaded a file from our nexus server by following this post: gradle - download and unzip file from url in my android project, first specifying the target:
compile 'net.myapp.gwt:MyAppGWT:1.0:android#zip'
and then I have this unzip task:
task unzip(type: Copy) {
def zipPath = project.configurations.compile.find {it.name.startsWith("net.myapp.gwt")}
println zipPath
def zipFile = file(zipPath)
def outputDir = file('src/main/assets/')
from zipTree(zipFile)
into outputDir
}
The problem is that the line
project.configurations.compile
generates the weirdest error. Applying it gives me following error:
Error:Could not find com.android.support:appcompat-v7:23.0.1.
Searched in the following locations:
file:/Applications/AndroioStudio.app/Contents/gradle/m2repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
file:/Applications/AndroidStudio.app/Contents/gradle/m2repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://maven.fabric.io/public/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://maven.fabric.io/public/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
https://nexus.domain.net/content/repositories/apps-releases/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
https://nexus.domain.net/content/repositories/apps-releases/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
Required by:
apps-android:app:unspecified
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
Now, all of a sudden it can't find
com.android.support:appcompat-v7:23.0.1
which isn't a problem if I remove that line.
#RaGe was right. Adding the libraries to our local repo server did the trick. Even though, as you state, this is a workaround and perhaps in the long run would be nice to find a better solution.
appcompat comes from your local sdk folder. But when you try to access configs.compile, gradle is trying to resolve all dependencies including appcompat from the external repos, and fails when it (unsurprisingly) doesn't find appcompat.
I'm not sure what the "right" solution is, but a possible workaround is to publish android sdk dependencies to your local maven or nexus repo. Here's one way to do that: github.com/simpligility/maven-android-sdk-deployer
Some answers from here might help too.
Lastly, it might be possible to treat your SDK folder as a local maven repo. See here.
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip