1

I have to store file in firebase storage.

My Gradle File:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.deadbrains.propertymanagement"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.github.jineshfrancs:CaptchaImageView:1.0'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-firestore:11.8.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true;
    }
}
apply plugin: 'com.google.gms.google-services' 

Here's my build.gradle (Project: appname):

buildscript {

    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}     

When i am uploading file error occur. This is my code for uploading file

private void uploadFile() {
        if (filePath != null) {
            pDialog = ProgressDialog.show( AddNoticeActivity.this ,"" ,"Wait..." ,false ,false );

            StorageReference riversRef = null;
            if (extension.equals( "docx" ) || extension.equals( "doc" )) {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "doc" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            } else if (extension.equals( "pdf" )) {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "pdf" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            } else {
                Random Number = new Random();
                int Rnumber = Number.nextInt( 100000 );
                String name = "pic" + Rnumber;
                riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );
            }
            strAttachment = riversRef.getPath();
            Log.d( "storage path : " ,strAttachment );

            riversRef.putFile( filePath )
                    .addOnSuccessListener( new OnSuccessListener <UploadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                            callAddNoticeService();
                        }
                    } )
                    .addOnFailureListener( new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception exception) {
                            Log.d( "Error" ,exception.getMessage() );
                            Toast.makeText( getApplicationContext() ,exception.getMessage() ,Toast.LENGTH_LONG ).show();
                        }
                    } )
                    .addOnProgressListener( new OnProgressListener <UploadTask.TaskSnapshot>() {
                        @Override
                        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

                        }
                    } );
        }
    }

It shows error at line

     riversRef = FirebaseStorage.getInstance().getReference().child( "Notice/" + name );

Error is

Fatal Exception: java.lang.NoClassDefFoundError Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;

When I upgrade the dependencies and it shows error :

error: resource android:attr/fontVariationSettings not found. Message{kind=ERROR, text=error: resource android:attr/fontVariationSettings not found.

error: resource android:attr/ttcIndex not found. Message{kind=ERROR, text=error: resource android:attr/ttcIndex not found.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
Unnati Patadia
  • 662
  • 3
  • 19
  • 39
  • Possible duplicate of [Android 3.1.1 - Failed resolution of: Lcom/google/android/gms/common/internal/zzbq;](https://stackoverflow.com/questions/49818415/android-3-1-1-failed-resolution-of-lcom-google-android-gms-common-internal-zz) – Mr. Patel Sep 05 '19 at 12:22

1 Answers1

2

Upgrade the following dependencies:

 implementation 'com.google.firebase:firebase-storage:11.8.0'
 implementation 'com.google.firebase:firebase-firestore:11.8.0'
 implementation 'com.google.firebase:firebase-core:16.0.9'
 implementation 'com.google.firebase:firebase-messaging:18.0.0'
 implementation 'com.google.firebase:firebase-auth:17.0.0'

into this:

 implementation 'com.google.firebase:firebase-storage:19.0.0'
 implementation 'com.google.firebase:firebase-firestore:21.0.0'
 implementation 'com.google.firebase:firebase-core:17.2.0'
 implementation 'com.google.firebase:firebase-messaging:20.0.0'
 implementation 'com.google.firebase:firebase-auth:19.0.0'

Check the latest version in the following link:

https://firebase.google.com/support/release-notes/android

After you update the dependencies you need to migrate you androidx, you can find how in the following link :

https://stackoverflow.com/a/57005161/7015400

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • These releases require also the androidx migration – Gabriele Mariotti Sep 05 '19 at 15:29
  • Then he can migrate..he's going to probably migrate later so bettee to do it now – Peter Haddad Sep 05 '19 at 15:57
  • Yes he can, maybe you can just add a note in the answer since he is using old support 27.x. – Gabriele Mariotti Sep 05 '19 at 15:59
  • I upgrade the dependencies and it shows error : error: resource android:attr/fontVariationSettings not found. Message{kind=ERROR, text=error: resource android:attr/fontVariationSettings not found. And error: resource android:attr/ttcIndex not found. Message{kind=ERROR, text=error: resource android:attr/ttcIndex not found. @PeterHaddad – Unnati Patadia Sep 06 '19 at 04:49
  • @UnnatiPatadia did you do this https://stackoverflow.com/a/57005161/7015400 also? – Peter Haddad Sep 06 '19 at 05:33
  • yes. i have done migrate still error occurs @PeterHaddad – Unnati Patadia Sep 09 '19 at 07:17
  • @UnnatiPatadia the `attr/fontVariationSettings` was added in version 28 https://stackoverflow.com/q/49208772/7015400 did you change also in build.gradle? Also clean the project and build again – Peter Haddad Sep 09 '19 at 07:18