Solucionado (ver solução)
Solucionado
(ver solução)
12
respostas

Não consigo criar um token

Meu projeto esta no firebase, mas não esta sendo gerado um token e nem consigo enviar uma notificação pois não ha nenhum aparelho cadastrado no firebase.

Segui todos os passos da configuração do Firebase, porem tive muitos problemas com a parte das dependências. Porem estou tendo agora esse problema co o link do firebase.

D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.

Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.alura.agenda"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.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.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-jackson:2.5.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
    implementation 'com.google.firebase:firebase-core:16.0.8'


}

apply plugin: 'com.google.gms.google-services'
12 respostas

AgendaInstanceIDService

package br.com.alura.agenda.firebase;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class AgendaInstanceIDService extends FirebaseInstanceIdService{

    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d("token firebase", "Refreshed token: " + refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        enviaTokenParaServidor(refreshedToken);
    }

    private void enviaTokenParaServidor(String refreshedToken) {
    }

}

OBS:

extends FirebaseInstanceIdService, onTokenRefresh() e .getToken(). Estão marcados como depreciados.

Oi Nailson, tudo bem?

O arquivo google-services.json está dentro do módulo app do projeto? Se ele estiver, me envia o projeto para que eu consiga investigar o possível problema.

Caso contrário, vá no projeto via console do Firebase, baixe o arquivo pelas opções do projeto e adicione no diretório app.

Sobre a implementação, tiveram algumas modificações com o tempo, e nos exercícios explico o que foi modificado, confira.

Tudo bem sim Alex!

Aqui está o link do github https://github.com/NailsonFerreira/agenda-android-studio.git

Obrigado pela atenção! Parabéns pela didática!

Oi Nailson, falta apenas seguir os passos do exercício que linkei, pois em vídeo temos a implementação antiga que é compatível com a versão do vídeo. Agora você faz tudo pela classe FirebaseMessaingService. Dá uma olhada na explicação do exercício e principalmente no commit que indica as diferenças com a nova implementação.

Precisando de ajuda é só avisar. Muito obrigado pelo feedback! :)

Então, apliquei a nova implementação e segui até as instruções do fim da aula 2, mas a conexão com o firebase ainda não funciona :( Fiz o debug percebi que por algum motivo que ainda não descobri, a classe AgendaInstanceIDService e seus metodos não estão sendo chamados.

(commits atualizados) https://github.com/NailsonFerreira/agenda-android-studio.git

$ adb install-multiple -r -t C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\instant-run-apk\debug\app-debug.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\dep\dependencies.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_4.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_9.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_3.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_5.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_8.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_7.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_6.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_1.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_2.apk C:\Users\nailson.ferreira\AndroidStudioProjects\Agenda-Web\agenda-android-studio\app\build\intermediates\split-apk\debug\slices\slice_0.apk 
Split APKs installed
$ adb shell am start -n "br.com.alura.agenda/br.com.alura.agenda.ListaAlunosActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 13471 on device emulator-5558
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/br.com.alura.agenda-1/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@br.com.alura.agenda-1@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
...
...
V/FA: Registered activity lifecycle callback
D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
I/FirebaseInitProvider: FirebaseApp initialization successful
I/InstantRun: starting instant run server: is main process
I/art: Starting a blocking GC Explicit
I/art: Explicit concurrent mark sweep GC freed 7616(616KB) AllocSpace objects, 0(0B) LOS objects, 46% free, 1175KB/2MB, paused 5.989ms total 90.205ms
V/StudioProfiler: Acquiring Application for Events
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W/art: Verification of com.google.android.gms.measurement.internal.zzao com.google.android.gms.measurement.internal.zzam.zzgn() took 161.709ms
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
       Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
V/FA: Registered activity lifecycle callback
D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
I/FirebaseInitProvider: FirebaseApp initialization successful
I/InstantRun: starting instant run server: is main process
I/art: Starting a blocking GC Explicit
I/art: Explicit concurrent mark sweep GC freed 7616(616KB) AllocSpace objects, 0(0B) LOS objects, 46% free, 1175KB/2MB, paused 5.989ms total 90.205ms
V/StudioProfiler: Acquiring Application for Events
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W/art: Verification of com.google.android.gms.measurement.internal.zzao com.google.android.gms.measurement.internal.zzam.zzgn() took 161.709ms
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
       Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
W/art: Verification of com.google.android.gms.measurement.internal.zzfd com.google.android.gms.measurement.internal.zzam.zzgo() took 260.060ms
I/art: Background sticky concurrent mark sweep GC freed 1933(751KB) AllocSpace objects, 1(20KB) LOS objects, 21% free, 1717KB/2MB, paused 15.695ms total 662.520ms
W/art: Verification of void com.google.android.gms.measurement.internal.zzam.zzgz() took 523.130ms
I/art: Background partial concurrent mark sweep GC freed 813(96KB) AllocSpace objects, 1(20KB) LOS objects, 40% free, 1866KB/3MB, paused 12.306ms total 134.879ms
V/FA: App package, google app id: br.com.alura.agenda, 1:487234219677:android:3a5ad5bdb69d3b6a
I/FA: App measurement is starting up, version: 14711
      To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
      To enable faster debug mode event logging run:
        adb shell setprop debug.firebase.analytics.app br.com.alura.agenda
D/FA: Debug-level message logging enabled
V/FA: Persisting first open: 1557148288750
V/FA: Updating deferred analytics collection: false
W/art: Verification of com.fasterxml.jackson.databind.ObjectMapper com.fasterxml.jackson.databind.ObjectMapper.addMixIn(java.lang.Class, java.lang.Class) took 129.497ms
V/FA: Checking service availability
V/FA: Service available
V/FA: Setting useService: true
V/FA: Connecting to remote service
W/Java7Support: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added
W/art: Verification of void com.google.android.gms.common.internal.zzf.<init>(com.google.android.gms.common.internal.zze, com.google.android.gms.common.internal.GmsClientSupervisor$zza) took 214.103ms
I/art: Background sticky concurrent mark sweep GC freed 4269(1213KB) AllocSpace objects, 6(120KB) LOS objects, 31% free, 2MB/3MB, paused 8.234ms total 341.410ms
W/art: Verification of void com.fasterxml.jackson.databind.ser.std.NumberSerializers.addAll(java.util.Map) took 213.383ms
V/FA: Connection attempt already in progress
I/art: Background sticky concurrent mark sweep GC freed 7131(572KB) AllocSpace objects, 1(20KB) LOS objects, 22% free, 2MB/3MB, paused 8.319ms total 90.581ms
I/FA: Tag Manager is not found and thus will not be used
D/OkHttp: --> GET http://192.168.1.20:8080/api/aluno
D/OkHttp: --> END GET
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=ListaAlunosActivity, firebase_screen_id(_si)=861003499530777025}]
D/: HostConnection::get() New Host Connection established 0xa3868a00, tid 13471
W/art: Verification of void com.google.android.gms.measurement.internal.zzag.<init>(java.lang.String, com.google.android.gms.measurement.internal.zzad, java.lang.String, long) took 172.828ms
D/: HostConnection::get() New Host Connection established 0xa39dc1c0, tid 13538
W/art: Suspending all threads took: 12.723ms
I/OpenGLRenderer: Initialized EGL, version 1.4
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
I/art: Background sticky concurrent mark sweep GC freed 3693(631KB) AllocSpace objects, 0(0B) LOS objects, 16% free, 2MB/3MB, paused 44.705ms total 955.943ms
D/EGL_emulation: eglCreateContext: 0xaf0a4e40: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xaf0a4e40: ver 2 0 (tinfo 0xaf0be9c0)
D/EGL_emulation: eglMakeCurrent: 0xaf0a4e40: ver 2 0 (tinfo 0xaf0be9c0)
W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 50244681
I/Choreographer: Skipped 83 frames!  The application may be doing too much work on its main thread.
D/OkHttp: <-- 200 OK http://192.168.1.20:8080/api/aluno (2738ms)
          Server: Apache-Coyote/1.1
          Content-Type: application/json;charset=UTF-8
          Transfer-Encoding: chunked
D/OkHttp: Date: Mon, 06 May 2019 13:11:39 GMT
D/OkHttp: {"alunos":[{"id":"0f48c21a-a855-4ef9-9219-5dbbb61d9447","nome":"Marcel ","endereco":"Movie Street","telefone":"987654321","site":"","nota":10.0,"desativado":0,"idCliente":0},{"id":"1ceb79d8-d296-4a03-84bd-0a991de50420","nome":"Abby Hammond","endereco":"Santa Clarita","telefone":"0003-3000","site":"www.servian-knights.com","nota":0.0,"desativado":0,"idCliente":0},{"id":"22607f5b-428f-45a4-8610-5886172db8af","nome":"Regina Phalange","endereco":"Street Carbage","telefone":"01234567","site":"www.smellycat.com","nota":10.0,"desativado":0,"idCliente":0},{"id":"689c40e2-4308-495a-b5a0-9b44770d3691","nome":"Franklin Aluizios Manford","endereco":"Connecticut","telefone":"01010101011111","site":"www.bardo.com","nota":10.0,"desativado":0,"idCliente":0},{"id":"81780e3e-32c3-4187-8767-29787c31235a","nome":"Kaleb Prior","endereco":"Abnegação","telefone":"000000001","site":"www.toerudition.com.go","nota":10.0,"desativado":0,"idCliente":0},{"id":"820a11d3-da5a-4af3-821c-e362a1e017d9","nome":"Dr. Drake Ramore","endereco":"Dias de nossas vidas","telefone":"0000-5555","site":"www.dro-drake-ramore.com","nota":10.0,"desativado":0,"idCliente":0},{"id":"e8aaaede-aea9-4866-a265-7d87dd51eae6","nome":"Janice M Bing","endereco":"Manhatan","telefone":"00000000000","site":"www.omg.com","nota":9.0,"desativado":0,"idCliente":0},{"id":"fdf21dfd-5dc0-41dc-a7ca-3437530911b3","nome":"Megan Vandergueld","endereco":"Miami","telefone":"99999000","site":"www.prada.com","nota":10.0,"desativado":0,"idCliente":0}],"momentoDaUltimaModificacao":"2019-05-06T10:11:39.656"}
          <-- END HTTP (1555-byte body)
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
I/art: Background partial concurrent mark sweep GC freed 1918(204KB) AllocSpace objects, 2(40KB) LOS objects, 39% free, 2MB/4MB, paused 9.990ms total 150.023ms
I/id do aluno: 0f48c21a-a855-4ef9-9219-5dbbb61d9447
               1ceb79d8-d296-4a03-84bd-0a991de50420
I/id do aluno: 22607f5b-428f-45a4-8610-5886172db8af
               689c40e2-4308-495a-b5a0-9b44770d3691
               81780e3e-32c3-4187-8767-29787c31235a
               820a11d3-da5a-4af3-821c-e362a1e017d9
I/id do aluno: e8aaaede-aea9-4866-a265-7d87dd51eae6
               fdf21dfd-5dc0-41dc-a7ca-3437530911b3
I/art: Background sticky concurrent mark sweep GC freed 686(26KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 4MB/4MB, paused 7.234ms total 83.906ms
I/art: Background partial concurrent mark sweep GC freed 1049(81KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 4MB/8MB, paused 7.293ms total 67.165ms
V/FA: Session started, time: 50257054
D/FA: Setting user property (FE): _sid
V/FA: Connecting to remote service
D/FA: Setting user property (FE): _sno
V/FA: Connection attempt already in progress
D/FA: Logging event (FE): session_start(_s), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=ListaAlunosActivity, firebase_screen_id(_si)=861003499530777025}]
V/FA: Connection attempt already in progress
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 3
V/FA: Inactivity, disconnecting from the service
solução!

Oi Nailson, vi o seu código, tá faltando ajustar o action do service do FirebaseMessagingService, você ainda deixou assim <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> sendo que tem que deixar com esse outro action aqui <action android:name="com.google.firebase.MESSAGING_EVENT"/>

Passei o fim de semana quebrando a cabeça, mas agora finalmente posso avançar no conteúdo.

Mais uma vez Parabéns pela didática! Obrigado Alex!

Que bom que conseguiu Nailson! Muito obrigado pelo feedback hehe

Precisando de ajuda, pode contar com agente ;)

Bons estudos.