How to create android studio library with fabric sdk? - java

I have integrated Twitter and all is done well.
But now I need to create a reusable component.
I.e.: a library using the fabric sdk in android studio.
We can get the fabric plugin from the Twitter developer site.
By using that I'm able to add sdk to an Android Studio project, but not to a library.
How to add this sdk to an Android Studio library project?

Define the classpath in your project's build.gradle as usual.
Add the dependencies to your library module as you would suspect.
Apply the io.fabric plugin in your app module. No way around this, that's by design. Fabric needs application ID, libraries don't have one.
EDIT: Due to manifest merging you are able to specify the API key meta-data (e.g. for Crashlytics) in your library's manifest.
EDIT 2: Looks like there's a page for it. http://support.crashlytics.com/knowledgebase/articles/456258-library-subproject-in-gradle
https://docs.fabric.io/android/crashlytics/build-tools.html#set-up-a-library-subproject

For creating reusable component with fabric sdk.update your gradle to something like this
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.library'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile('com.twitter.sdk.android:twitter:1.3.2#aar') {
transitive = true;
}
}
Do rebuild your project after updating gradle file.you wil get the skd access now.

Related

ERROR: Gradle DSL method not found: 'imlementation()'

My app is not working after I updated my android phone to Android 10. So I migrated my app to androidx. Now I am trying to update my gradle from 2.3.1 to 3.5.1.
This is my build.gradle(Project:) file -
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
My build.gradle(Project:) file is -
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "....."
minSdkVersion 19
targetSdkVersion 29
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
imlementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation files('....')
implementation files('....')
implementation files('....')
implementation files('....')
}
This is the Error I get -
ERROR: Gradle DSL method not found: 'imlementation()'
Possible causes:
The project '.....' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade plugin to version 3.5.1 and
sync project
The project '...' may be using a version of
Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin
I am new to android development. I am using android studio.
Thank you in advance.
You made a typo in your first implementation declaration. imlementation -> implementation.
Change imlementation
to
implementation

Android studio gradle .pom file download error

hi im from iran and we cant use gradle without proxy but now i cant use it with proxy too i dont know why i change every thing but still i cant i have my Cicsco Connection on please help me this is my gradle files
module build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "test.example.test.com.test"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
// google support library ---------------------------------------------------------------------
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
}
and project gradle
buildscript {
repositories {
google ()
jcenter{ url "http://jcenter.bintray.com/" }
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google ()
jcenter{ url "http://jcenter.bintray.com/" }
maven { url 'http://repo1.maven.org/maven2' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this is the errors i got
1:Cause: dl.google.com:443 failed to respond
2:org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'
3: Could not GET 'http://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'
4: Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'.
Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it. Your problem is setting up the proxy. You just need to set some variables in $projectDir/gradle.properties, for example:
#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
This can be used to download dependencies without proxy. If you want to use a proxy for you can use the code as below instead of above code.
systemProp.https.proxyPort=3128
systemProp.http.proxyHost=192.168.16.2
systemProp.https.proxyHost=192.168.16.2
systemProp.http.proxyPort=3128
Proxy port and host can be changed as you want.
i solve the problem by just edit the gradle properties i added a proxy and i forgot that was my problem

Android Studio cannot find classes after upgrading version of dependency

I have two projects: library and app. I have previously uploaded library to jCentre, and library is listed as an external dependency of app in its build.gradle file. Recently I published a newer version of library and updated the dependency version code in app's build.gradle file, but when I did this Android Studio could no longer find any of the classes from library.
To test the library, I created an entirely new project and added library as a dependency. In this scenario Android Studio finds the classes just fine. I've compared every line of the build.gradle files: They have the same min and target SDK version, they have the same proguard config, they're literally identical. They projects are also using the exact same version of the android plugin and the exact same gradle version.
I also tried entirely deleting app from my machine and re-checked it out from git. This did not solve the problem. I've tried all the usual steps of cleaning the project and rebuilding the project, deleting all build files, invalidating caches, etc.
So can anyone tell me why Android Studio cannot find any of the library classes after upgrading the dependency version?
Here is the gradle.build file in the new test project:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
versionCode 11
versionName "3.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}
Here's the build.gradle file in the app project:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.matthew-tamlin:android-utilities:2.1.0' // this is library
}
You can see that they're virtually identical, so why can one project find the classes from the library but the other cannot?
So I never discovered why this is an issue, but I found a workaround. I created a new project in Android Studio and copied all the src directories and build.gradle files from the existing project. I also copied the hidden git folder and all git ignore files. I didn't copy the gradle wrapper, the gradle file or the generated builds. I don't know why this fixed the problem, it must be a bug in gradle or Android Studio.

How to pack Android Gradle app to *.jar or *.aar file

I created Android App with some gradle dependencies. Now I want to create from this project *.jar (without resources and add them separately) file or *.aar file.
I tried to create new library project (with build.xml), copied my *.java and res files and run ant jar, I'm fixing problem one by one. Is there any better solution to do this?
You need to make two modules. The first module would be the jar. This should be POJOs (Plain Old Java Object) and nothing Android. The second module would be the aar. This could depend on your first project but add on the Android specific code / resources.
Then your project (MyApp) structure would look like this
MyApp/
MyApp/build.gradle
MyApp/settings.gradle
MyApp/PoJoProject/
MyApp/PoJoProject/build.gradle
MyApp/AndroidProject/
MyApp/AndroidProject/build.gradle
Then your settings.gradle file would look something like this:
include ':PoJoProject', ':AndroidProject'
Now in the modules
In MyApp/PoJoProject/build.gradle you will want to apply the java plugin. This module will build to the desired jar format that can be ran anywhere on the normal JVM.
plugins {
id 'java'
}
version '1.00'
group 'com.example.multimodule.gradle'
repositories {
jcenter()
}
dependencies {
compile 'com.google.code.gson:gson:2.5'
testCompile 'junit:junit:4.12'
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
In the MyApp/AndroidProject/build.gradle you want to apply the android plugin. This module will build to the desired aar format and can only be used as an Android dependency.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
}
}
apply plugin: 'com.android.application'
// version could be different from app version if needed
// `version` & `group` could also be in the top level build.gradle
version '1.00'
group 'com.example.multimodule.gradle'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.multiproject.gradle.android"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
// let the android `aar` project use code from the `jar` project
compile project(':PoJoProject')
testCompile 'junit:junit:4.12'
}

Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals

I'm new to Android and I can't get my first app to run. Whenever I try, it's throwing this error:
Android gradle :app:packageDebug FAILED: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.
I googled it and I found many questions there. As many said, this problem is probably due to the fact that I have multiple dependencies on BouncyCastle in my project. I tryed to remove the .gradle folder both in my project and in my local folder so I could download again the jars from the repository but nothing has changed. I also double checked that my JAVA_HOME is set and it's pointing to a 1.7 version. I tryed to gradle :app:clean and gradle :app:dependencies to see if I was missing something but still... I can't see any dependency from BouncyCastle... Can anybody help me?
Also, this problem occured without me changing any code... The app successfully worked yesterday and now is giving me this error... I don't get it. Thank you.
EDIT
gradle.build
Top-level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.aurasphere.provaactionbar"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile project(':volley')
compile files('libs/gson-2.2.2.jar')
}
Module volley:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion = '21.1.0'
}
apply from: 'rules.gradle'
rules.gradle for module volley:
apply plugin: 'com.android.library'
I've solved this problem myself just by changing the JDK I was using from x32 to x64 and now is compiling correctly.

Categories