Manually adding entries to OssLicensesMenuActivity using oss-licenses plugin with Android - android

I'm using the oss-licenses plugin (Android - Including Open Source Notices) for my Android app to gather the license information from all the open source repositories being used.
But some publishers have not included the <licenses> tag in their repository's POM file. This is why the plugin won't find the license file and these libraries are missing when using OssLicensesMenuActivity to display the listing.
Is there a way to enter additional entries for OssLicensesMenuActivity?

There is still no easy way to do this. However, there is an open merge request that would add this feature.
Anyway, I solved it with a workaround. First, create an empty library and publish it to your local maven(or some other maven repo), and then add the library as a dependency.
You can publish the library to the local maven repo using this plugin.
The gradle file of the library would look like this:
publishing {
publications {
release(MavenPublication) {
groupId = "com.stephan"
artifactId = "mylib"
version = "1.0.0"
pom {
name = 'The name I want to show in the list'
licenses {
license {
name = 'The license'
url = 'https://url.to.license'
}
}
}
}
}
}
And the command to publish to the local maven repo: ./gradlew :nameoflibmodule:publishToMavenLocal
In the app project this can be easily added as a dependency with the usual implementation 'com.stephan:mylib:1.0.0' (also add mavenLocal() to the repositories in the build file)
The library can be empty, the only important part is that there is a pom file containing a <licenses> element. This can be verified by looking into the local maven repo at $USER_HOME/.m2/repositories/
For my example this would be $USER_HOME/.m2/repository/com/stephan/mylib/1.0.0/mylib-1.0.0.pom

Related

importing an existing JAR or AAR as new project module

how to import JAR or AAR package as new project module in A new Android Studio Arctic Fox | 2020.3.1 Canary 9 ?
please let me know.
This works on Android Studio Arctic Fox Beta 02
Step 1 : Navigate to, File -> Project Structure. You can also press Ctrl+Alt+Shift+S
You will see a window just like below.
Step 2 : Click On app module as shown in image
Step 3 : Click on + icon as marked in image
Step 4 : You will see option to select jar/aar dependency. Click on it
You will see another window just like above asking you to specify path. Specify the path in which you kept the aar/jar file and hit Ok.
That should work
You can directly implement using JAR/ARR file path.
implementation files('/File Path/file.aar')
For Android Studio Bumblebee, original answer given here
I have followed steps suggested by the Android developer site:
Copy .aar file into the libs folder of the app
File -> Project Structure... -> Dependencies
Click on "+" icon and select JR/AAR Dependency and select app module
Add .aar file path in step 1.
Check your app’s build.gradle file to confirm a declaration.
Step 1: Put your aar file in the libs folder. And let’s take the file name is supernover.aar as an example.
Step 2: Put the following code in your Project level
build.gradle file,
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
and in the app level module write the below code,
dependencies {
Implementation(name:'supernover', ext:'aar')
}
Step 3: Then Click sync project with Gradle files.
If everything is working fine, then you will see library entry is made in build ->intermediates -> exploded-aar.
In my opinion, the best way to do this is to deploy the jar/aar to a local maven repository. if you install maven, you can use the mavenLocal() repository in gradle and read from there as with any other repo, regardless of the IDE you are using. All versions of Android Studio will work, all version of IntelliJ will work, VSCode will work, the command line will work, etc. Another advantage is, you'll be able to swap versions of the library as you do with all the others, just change the version in gradle (after deploying the new one), and will work for all your projects. Putting jars/aars manually into a project is just a bad practice, and reaaally outdated to top.
Once you installed maven, type this in your terminal:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Where you swap aar and jar depending on the type. The package name, group ID and library name are up to you, anything will work. I would use the library's package and name, and version 1.0 if you don`t have a version.
Here's an example link. Is old, but the process is the same. mvn install, then consume from mavenLocal().
For anyone in search of a solution still.
Create a new android Application project.
Convert new project into a standalone Library module.
Add maven-publish plugin to the module-level build.gradle
Connect your project to your Github repository (or create a new one).
In the module-level build.gradle, implement the Github Packages authentication flow. I'm using 'zuko' as an example - replace every instance of that name with your Github login.
android {
...
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/zuko/[git-repository]")
credentials {
username = 'zuko'
password = 'token' // this is a Git Personal Access Token
}
}
}
publications {
release(MavenPublication) {
groupId 'com.zuko.libraries'
artifactId 'choose-a-name'
version '1.0.0'
artifact("$buildDir/ogury-mediation-mopub-5.2.0.aar")
// you can actually put the artifact anywhere you want.
// This is the location of where you place your .aar file
}
}
}
...
}
If everything is connected properly, save your work, and run the the task: ./gradlew publish. The error logs are straightforward so just defer to the instructions and Google for more assistance.
To install a successfully published package into your desired project, use the same auth procedure for publishing.repositories, you don't need the second half, publishing.publications.
example: implementation 'com.zuko.libraries:choose-a-name:1.0.0'
You could configure a repository in you buildscript that looks for dependencies in a local directory
Use this to register a local directory as repository in your app module's build.gradle where libs is a directory under app module (<project>/app/libs/)
buildscript {
repositories {
flatDir { dirs 'libs' }
}
}
then declare your dependencies from the local file tree you registered earlier
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
This will include all jar/aar artifacts present under libs directory to be included in your module's dependencies.
PS: Local jar/aar artifacts will expect any transitive dependencies to be on the classpath unless they are fat-jars (package all transitive dependencies within the artifact), so these need to be added explicitly as dependencies.

How to version local gradle dependencies?

My Android project contains a library that is shipped as AAR file.
There are multiple options to include local AAR files.
I can declare a file dependency:
implementation files('libs/mylib.aar')
Or I can put the AAR into another module and then use a project dependency:
implementation project(':mylibmodule')
However, I want to specify the exact version of my library:
mylib:1.0.0
Unfortunately, I do not know how to specify the version without using some remote repository.
Note that I do not want to upload the library to JitPack, MavenCentral or similar.
All I want is to specify the version of a local AAR file.
Update
The AAR file is a Zip-File with the following content:
/proguard.txt
/R.txt
/AndroidManifest.xml
/public.txt
/classes.jar
/res/values/values.xml
Note that the AndroidManifest.xml contains the version of the library.
However, I assume that gradle always expects a pom file for the versioning information.
I realized that gradle allows to specify a local Maven repository at a specific path:
repositories {
maven {
url uri("${projectDir}/mylibdir")
}
}
To use a local Maven repository, I need to build my library as a Maven artifact. To create a Maven artifact, it suffices to create a POM file in the right subfolder.
The AAR file remains unchanged since Maven does not care about the artifact format.
Creating a Maven artifact can be automated with the maven-publish plugin, e.g.:
apply plugin: 'maven-publish'
publishing {
publications {
myRelease(MavenPublication) {
groupId 'com.foo'
artifactId 'my-artifact'
version '1.0.0'
artifact("$buildDir/outputs/aar/my-artifact.aar")
}
}
repositories {
maven {
url "$buildDir/repo"
}
}
}
However, since I do not really need to use Maven, the simpler choice is to add the version to the AAR file name.
I did this with the following snippet in the build.gradle of my library:
android.libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = "${archivesBaseName}-${variant.name}-${defaultConfig.versionName}.aar"
}
}

Maven publication of multi-modules android library

I am working on an Android SDK made of multiple library modules and a test app module:
mySDK
|-test-app
|-lib-core
|-lib-ui
|-...
I would like to publish it on a Maven repository, with all library modules embedded (but not the test-app).
I know how to publish a single library module using Maven Publish Plugin but can't figure out how to make a Maven publication containing multiple library modules.
How would you do that ?
Just upload each module as a standalone module.
It is not mandatory to upload all the modules at the same time, the dependencies are just described in the pom file.
It can be useful putting a base script in a single gradle file with some common settings and properties (you can read them from a gradle.properties file), something like:
rootFolder/maven_push.gradle:
apply plugin: 'maven'
//....
pom.artifactId = POM_ARTIFACT_ID
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
//...
}
//...
and then in each module/build.gradle file add:
apply from: '../maven_push.gradle'
Each module is a library by itself, so configure each one of them (besides the app) to be packaged as AAR files and deployed to the desired repo. If you are going to use the Maven publish plugin, just apply the steps to each module(to the module's build.gradle files). A good practice is to centralize the groupId and version values, perhaps in the gradle.properties file, or in the main gradle file. Same procedure applies to other plugins, like the android-gradle-maven plugin.

How to deploy android library on gradle or google repositry?

I've got few libraries which I want to deploy on Gradle(google repository, etc)
so that anybody can access it using Gradle as we do in android studio app.gradle file
Eg : implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
I want to know the process of deploying, I already have the libraries.
Thank you
1. Make library module in Android Studio [ Assumed that you have prepared ]
2. Create Space on Bintray
Fill in the required information as shown below with your exact module name and your GitHub repo links and click on “Create Package”.
Congrats! You have successfully completed the second step.
3. Upload your library on Bintray and JCenter
Now you need to configure your library so that you can upload it to Bintray followed by JCenter.
Modify the project build.gradle file by adding these below dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
Add your Bintray authentication details in the local.properties file. That information should not be pushed to the version control system.
bintray.user= “YOUR USERNAME”
bintray.apikey= “YOUR API KEY”
You can find both credentials in your account by following these steps-
Open your Bintray account, click on your name and then click edit under your name and then the API Key tab.
Now we need to modify our module build.gradle file. Open the file and modify according to the below-mentioned steps.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
ext {
bintrayRepo = 'Utility' // your repo name
bintrayName = 'time-utils' // has to be same as your library module name
publishedGroupId = 'com.timeutility' // your module package name
libraryName = ‘time-utils’
artifact = 'time-utils' // has to be same as your library module name
libraryDescription = 'A set of methods used to manipulate time object'
siteUrl = 'https://github.com/androidCode/time-utils'
gitUrl = 'https://github.com/androidCode/time-utils.git'
libraryVersion = '1.0'
developerId = ‘sachit’
developerName = Sachit
developerEmail = 'sachit.wadhawan#quovantis.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
android {
// -------- your target version and all required configuration. These are normal as for other projects and generate by android studio itself
}
dependencies {
// Your dependecies
}
// add it to the bottom of the file
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
Sync the project. Once everything is configured, run the command below in your terminal, in root of the project.
./gradlew clean build install bintrayUpload
Shout Hurray! if it shows BUILD SUCCESSFUL.
Check your package in the Bintray web interface. You will see a change in Versions area. Now it needs to be pushed to JCenter. Now once your project is up on Bintray, simply hit “Add to JCenter” button to sync with JCenter.
It may take a few hours before your request has been accepted. When it happens, you should get a notification via email and also see the jCenter badge in your package details under the “Linked to” section.
Congratulations! Your library is now on jCenter!!! You can give the gradle path into your project now. For example my dependency looks like this:
implementation 'xxxxxxxxxx:xxxxxx:1.0'
Thank You :)
You need an artifactory. You can use public ones like maven-central, jitpack or create your own by using JFrog.
Then update your library project that able to work with maven to create an artifact.
After that, you are ready to publish.
I would suggest to use jitpack if you are not familiar since its a huge topic.

How to publish android library to subversion and use it on projects

There are many posts about publishing android library in github. Is there any way to publish android library to the svn?
EDIT:
I have created a libray and build the aar file. I have imported the aar file in to a tag of the svn. (Ex: svnpath/project/tags/library0.0.1.aar)
I want to use this library in a separate project. I want to use this library as
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
like this. how can i achieve this?
As discussed in the comments, Subversion (SVN) is not an appropriate tool for what you are trying to achieve. Subversion is a version control system which manages the versioning of source code files and associated resources, much in the same manner as Git does.
What you are looking for is a dependency management system using Maven, for example Artifactory. This will allow you to publish your .aar files to either a public-facing or private repository and import those dependencies into your build.gradle file. Unfortunately the process for setting up such a service is too broad for the scope of this question, but once you have it up and running you can add it to your build.gradle file under the repositories section:
repositories {
maven {
url "<url of Maven server>"
credentials {
// If you choose to use authentication
username = <your artifactory username>
password = <your artifactory password>
}
}
}

Categories

Resources