Add a dependency to gradle.build from CLI - android

many dependency management tools have very convenient cli helpers for saving new dependencies in the configuration files.
For instance, npm install --save express will save the info about express dependency to the project's package.json file.
I wonder if there is an equivalent in the gradle world? In particular, I'm looking for a way to add fabric dependency to my build.gradle from cli.
Here the changes that needs to be done to my build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}

Related

Do you add multiple buildscripts in `app/build.gradle` for manual Android linking in React Native?

In the section adding the gradle plugin for this React Native component, it tells me to add the following code to app/build.gradle:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
However, I've added other components that said to add similar code. For example, this component says to add this code:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
What I Want To Know:
How do you add the code for both of these components into the same project?
You should have one build script and add all the repositories in the repositories block and the dependences in the dependencies block
it should be like this
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
for the apply plugins should be in the build.gradle for the app module
add them on the top
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "your.app.package"
}
}

Illegal class file: Class module-info is missing a super type. Class file version 53

When I add firebase perf dependency into my project i am getting this error Illegal class file: Class module-info is missing a super type. Class file version 53.
My Gradle and google services project-level dependencies are
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
and I followed the exact steps mentioned in their docs https://firebase.google.com/docs/perf-mon/get-started-android.
I have tried clean and rebuild and clearing the Android Studio cache.
And also tried similarly issue resolution from StackOverflow
Project level build gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
classpath 'com.google.firebase:perf-plugin:1.3.1' // Performance Monitoring plugin
}
}
allprojects {
repositories {
google()
jcenter()
}
}
App level build gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
jcenter()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.31.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
// Apply the Performance Monitoring plugin to enable instrumentation
apply plugin: 'com.google.firebase.firebase-perf'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
maven {
url 'https://maven.google.com'
}
}
dependencies {
// Not added all dependencies , Just the firebase one SINCE ITS PRETTY LONG
implementation 'com.google.firebase:firebase-perf:19.0.0'
}
Adding this to your app-level build.gradle file solves the problem temporarily
debug {
FirebasePerformance {
// Set this flag to 'false' to disable #AddTrace annotation processing and
// automatic HTTP/S network request monitoring
// for a specific build variant at compile time.
instrumentationEnabled false
}
}
EDIT as per other answers and comments
Change the gradle plugin to 3.6.0 to resolve it as it has been fixed in that version
FYI, this was an AGP bug...it's been fixed in AGP 3.6
On updating build Gradle from 3.5.1 to 3.6.0 fixed my issue.
Also remove this from gradle.properties if you happen to have it there for any reason:
android.enableR8=false
(I got the error even with com.android.tools.build:gradle:4.1.2 if the above line was present)

Resolving Artifacts from bintray via gradle (non jcenter)

I've deployed artifact to bintray as it whitten in documentation (using their plugin). All looks fine. It is opened in browder, structure looks fine: https://dl.bintray.com/flymob/maven/
Now I want to use it via gradle in Android Studio before publishing to jcenter(). I've read their documentation https://bintray.com/docs/usermanual/formats/formats_mavenrepositories.html#_working_with_gradle
I've tried:
buildscript {
repositories {
jcenter()
maven {
url "https://dl.bintray.com/flymob/maven"
}
}
}
and
compile 'flymob-sdk-sample:FlyMobSdk:1.3.0'
or
compile 'flymob-sdk-sample:FlyMobSdk:1.3.0#aar'
I'm getting error:
Failed to resolve: flymob-sdk-sample:FlyMobSdk:1.3.0
What am I doing wrong?
you added "https://dl.bintray.com/flymob/maven" inside the buildscript section. Those are the repos used by the buildscript (a.k.a. gradle script) only. Those are the repos where the system will find the plugins from apply plugin
to fix it is easy. Just move it to the repositories on the "root" of the script. Something like:
buildscript {
repositories {
// repos for the build script
jcenter()
... etc
}
dependencies {
// dependencies from the plugins from the build script
classpath 'com.android.tools.build:gradle:2.1.2'
... etc
}
}
apply plugin: 'android-sdk-manager'
apply plugin: ... etc
repositories {
jcenter()
maven { url "https://dl.bintray.com/flymob/maven" } <<<<< HERE
}
dependencies {
compile ... etc

Android Studio. Twitter SDK integration

I've tried to integrate Twitter SDK to my android-application. According official documentation (http://docs.fabric.io/android/twitter/twitter.html) I've added to build.gradle dependencies:
compile('com.twitter.sdk.android:twitter:1.6.0#aar') {
transitive = true;
}
But I've got error in Android Studio:
Failed to resolve: com.twitter.sdk.android:twitter:1.6.0
Could you please help me with it. Thank you.
I think the problem might be due to some of the other stuff Fabric.io requires to work.
I recommend you plug in their Android Studio IDE plugin, as it handles everything pretty seamlessly! https://dev.twitter.com/fabric/android/integrating
According to this, have you updated your gradle file to include:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
// The Fabric Gradle plugin uses an open ended version to
// react quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
Not sure if you need ALL of it, but you probably need some of it. I needed to add these when using Crashlytics, because Twitter hosts some of their own repos.

Failed to resolve: com.twitter.sdk.android:tweet-composer

compile('com.twitter.sdk.android:tweet-composer:0.8.0#aar')
{
transitive = true;
}
i got gradle from https://dev.twitter.com/twitter-kit/android/compose
But when Sync the Android Studio project following error is coming ..
Error:(53, 13) **Failed to resolve: **com.twitter.sdk.android:tweet-composer:0.8.0****
Show in FileShow in Project Structure dialog
As was described on twitter, you have to change some parts in your module build.gradle.
In your module you can use:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// The Fabric Gradle plugin uses an open ended version to
// react quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
I suggest you installing the Android Studio plugin.
It helps you to configure the gradle script.
This help me
https://dev.twitter.com/twitterkit/android/installation
dependencies {
// Include all the Twitter APIs
compile 'com.twitter.sdk.android:twitter:3.0.0'
// (Optional) Monetize using mopub
compile 'com.twitter.sdk.android:twitter-mopub:3.0.0'
}
OR
enter code dependencies {
compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-ui:3.0.0'
compile 'com.twitter.sdk.android:tweet-composer:3.0.0'
compile 'com.twitter.sdk.android:twitter-mopub:3.0.0'
}

Categories

Resources