import com.firebase.client.Firebase in Android 2.3.3 - android

I am creating an application class to use Firebase in my complete application. However in the import line error occurs highlighting 'firebase' in red.
I have looked everywhere but cannot make out the problem.
Code:
package com.mobility.mobilityindia;
import android.app.Application;
import com.firebase.client.Firebase; <--- firebase is red here
public class MobilityIndia2 extends Application{
#Override
public void onCreate() {
super.onCreate();
Firebase.setAndroidContext(this); <---- Firebase is red here
}
app level gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig
{
applicationId "com.mobility.mobilityindia"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
String googleSupportVersion = '26.+'
String googlePlayServicesVersion = '11.0.2'
compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
compile "com.google.firebase:firebase-auth:$googlePlayServicesVersion"
compile "com.android.support:appcompat-v7:$googleSupportVersion"
compile "com.android.support:support-v4:$googleSupportVersion"
compile "com.google.android.gms:play-services:$googlePlayServicesVersion"
compile "com.android.support:design:$googleSupportVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
top level gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}

The code you have is for an old version of the Firebase SDK (1.x or 2.x), while you're importing the latest version.
If you follow the latest documentation or the latest Android codelab, you won't need the Firebase.setAndroidContext() anymore and will get imports that start with com.google.firebase.

Related

Butterknife NullPointerException with ViewPager [duplicate]

When i'm trying to do this:
...
public class LoginActivity extends AppCompatActivity {
#BindView(R.id.login_form) View loginForm;
...
loginForm is getting null. I tried to follow other answers and nothing worked (this for example). I also did exactly what it said in the butterKnife configuration page and it didn't work. What am I doing wrong?
module gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "name"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Project gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.6.0'
Probably, you forget to put this line:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
...
}
In onCreate you have to call
ButterKnife.Bind(this)
before you use the views
Also add mavenCentral() to repositories in gradle
repositories {
jcenter()
mavenCentral()
}

Multi desk error when I integrate linked In library to in my android project

I am getting error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I added linked in sdk successfully but when I compile project(':linkedin-sdk') then give me error i tried to resolve this error i also try multiDexEnabled true but still get error this is my app.gradle file
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'http://developers.quikkly.io/nexus/repository/maven-releases/' }
maven { url 'http://developers.quikkly.io/nexus/repository/maven-snapshots/' }
maven { url 'https://maven.fabric.io/public' }
mavenLocal()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.27.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
compile 'com.brucetoo.pickview:library:1.2.3'
compile 'com.caverock:androidsvg:1.2.1'
compile 'commons-io:commons-io:2.5'
// Pretty color picker
compile('com.thebluealliance:spectrum:0.7.1') {
// spectrum uses older support libs, override these with latest.
exclude group: 'com.android.support'
}
compile('net.quikkly.android:quikklycore-lib:1.2.0#aar') {
transitive = true
}
compile 'net.quikkly.android:quikkly-lib:1.2.0#aar'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
// Include all the Twitter APIs
compile 'com.twitter.sdk.android:twitter:3.1.1'
// (Optional) Monetize using mopub
compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
implementation 'com.android.support:support-v13:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
}
this is my linkedin gradle file
allprojects {
repositories {
mavenCentral()
}
}
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'android-library'
android {
sourceSets {
androidTest {
setRoot('src/test')
}
}
compileSdkVersion 17
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
configurations {
}
dependencies {
compile 'com.android.support:support-annotations:20.0.0'
compile 'com.android.support:support-v4:21.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/volley.jar')
androidTestCompile('junit:junit:4.12')
}
I used android studio 3.0 RC 2 with cannery if any kind of help or suggestion please let me know thank in advances
EDIT:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Use this in your linkedin gradle file:
allprojects
{
repositories
{
maven
{
url "https://maven.google.com"
}
}
}
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
public class ApplicationClass extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
}
}
I am putting up the complete MultidexApplication code
app gradle
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Caution: Do not execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. Multidex tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files.

how does the gradle dependencies work, i can not find any function relate with it in the gradle source code

how does the gradle dependencies work, i can not find any function relate with it in the gradle source code.
please help me , I googled this but found nothing...
dependencies {
}
gradle dependencies work from build.gradle(Module:app)
buildscript {
repositories {
....
}
dependencies {
...........
}
}
apply plugin: 'com.android.application'
apply plugin: '..'
repositories {
.....
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "your pkg name"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
//Here you can add your dependencies
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
........
}

can't call kotlin module from java module

I want to have an android app in java, but one library module in kotlin. However when I try to run the app in my phone, there's an error saying that it can't find my Kotlin class. This is my kotlin class:
package com.example.mylibrary
import android.util.Log
class A {
fun helloWorld(){
Log.d("Kotlin", "Hello World!")
}
}
and gradle file for my kotlin module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
buildscript {
ext.kotlin_version = '0.6.+'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
Here's my main activity:
package com.example.uisample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.mylibrary.A;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
A obj = new A();
obj.helloWorld();
}
}
Notice how android studio imports com.example.mylibrary.A instead of com.example.mylibrar.Akt as the reference says. Android studio reports no errors before compiling.
Gradle file for app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.uisample"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':mylibrary')
}
After running the project, gradle throws this error: "cannot find symbol class A". What am I doing wrong?
A few things:
Apply the kotlin-android plugin to your library module build.gradle (see the docs):
apply plugin: 'kotlin-android'
As it stands now, you're not even telling gradle to compile Kotlin files.
Your buildscript block should probably be at the top-level build.gradle rather than the module build.gradle.
Consider updating the fully released version of Kotlin 1.0.1-2
For that, you need to add
buildscript {
ext.kotlin_version = '1.4.30' <-- This line
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" <-- This line
}
}
In the gradle.build (project)
and then add the
apply plugin: 'kotlin-android'
In the gradle.build (App)

Android Gradle: How to access java class from module in build.gradle script file?

I want to develop a small android library and share it later with the community. I want to use javassist, especially the project morpheus to manipulate the bytecode of annotated classes during the build time.
Currently im stuck while i want to use my TestTransformer class from the Library within the TestApplications build.gradle script. The TestTransformer.java is defined as usual within the library project.
library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.github.stephanenicolas.javassist:javassist-build-plugin-api:1.0.0'
}
application build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'com.android.application'
apply plugin: 'morpheus'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "example.com.testapplication"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
//compile 'com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8'
compile project(':testlibrary')
}
morpheus {
//transformers = new example.com.testlibrary.TestTransformer()
transformers = new com.example.testlibrary.TestTransformer()
}
TestTransformer.java
import javassist.build.IClassTransformer;
import javassist.build.JavassistBuildException;
public class TestTransformer implements IClassTransformer {
#Override
public void applyTransformations(CtClass ctClass) throws JavassistBuildException {
}
#Override
public boolean shouldTransform(CtClass ctClass) throws JavassistBuildException {
return false;
}
}
Now i get the following error when i try to sync the projects with gradle files:
Error:(44, 0) Cause: startup failed:
build file 'C:\Users\MyUser\AndroidStudioProjects\TestApplication\app\build.gradle': 44: unable to resolve class com.example.testlibrary.TestTransformer
# line 44, column 20.
transformers = new com.example.testlibrary.TestTransformer()
1 error
Is it even possible to achieve my planned propose?
Thanks alot!

Categories

Resources