Android Question Problem when running my app with Firebase push notifications

Discussion in 'Android Questions' started by Almog, Apr 13, 2019.

  1. Almog

    Almog Active Member Licensed User

    Hello,

    I tried to use Push notifications with Firebase, throe Erel's video tutorial.

    When running in release mode, this error occurred at the compiler:

    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/AppMeasurement;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/AppMeasurementContentProvider;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zza;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzaa;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzab;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzac;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzad;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzae;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/android/gms/measurement/internal/zzaf;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:696)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
    at com.android.dx.command.dexer.Main.runDx(Main.java:293)
    at com.android.dx.command.dexer.Main.main(Main.java:249)
    at com.android.dx.command.Main.main(Main.java:94)
    Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:688)
    ... 4 more



    Does anybody know what the problem is and how to fix it?

    Thanks in advance...
     
  2. DonManfred

    DonManfred Expert Licensed User

    Post your manifestcode

    Maybe post all libs you are using.

    Best is to start implementing in a small project.

    Also post all additionallibs lines you are using in your project
     
  3. Almog

    Almog Active Member Licensed User

    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "5" android:targetSdkVersion="26"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    CreateResourceFromFile(Macro, Themes.DarkTheme)
    'End of default text.
    AddPermission(android.permission.INTERNET)
    AddPermission(android.permission.WAKE_LOCK)

    AddManifestText(<uses-permission
       android:name=
    "android.permission.WRITE_EXTERNAL_STORAGE"
       android:maxSdkVersion=
    "18" />
    )

    AddApplicationText(
      <provider
      android:name=
    "android.support.v4.content.FileProvider"
      android:authorities=
    "$PACKAGE$.provider"
      android:exported=
    "false"
      android:grantUriPermissions=
    "true">
      <meta-data
      android:name=
    "android.support.FILE_PROVIDER_PATHS"
      android:resource=
    "@xml/provider_paths"/>
      </provider>
    )
    CreateResource(xml, provider_paths,
       <files-
    path name="name" path="shared" />
    )

    CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
    CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
    CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
    Core (9.00)
    Dialogs (4.01)
    FirebaseAnalytics (1.02)
    FirebaseNotifications (1.21)

    JavaObject (2.05)
    JSON (1.10)
    OkHttp (1.22)
    OkHttpUtils (2.82)
    Phone (2.50)
    RuntimePermissions (1.10)
    StringUtils (1.12)
    XUI (1.90)

    The problem happened only after adding Push Notifications option to my project. I tried compiling it before and it worked.

    FirebaseMessaging service:
    Code:
    #Region  Service Attributes
        
    #StartAtBoot: False
        
    #End Region

    Sub Process_Globals
        
    Private fm As FirebaseMessaging
    End Sub

    Sub Service_Create
        fm.Initialize(
    "fm")
    End Sub

    Public Sub SubscribeToTopics
        fm.SubscribeToTopic(
    "general"'you can subscribe to more topics
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
        Sleep(
    0)
        
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
    End Sub

    Sub fm_MessageArrived (Message As RemoteMessage)
        
    Log("Message arrived")
        
    Log($"Message data: ${Message.GetData}"$)
        
    Dim n As Notification
        n.Initialize
        n.Icon = 
    "icon"
        n.SetInfo(Message.GetData.Get(
    "title"), Message.GetData.Get("body"), Main)
        n.Notify(
    1)
    End Sub

    Sub Service_Destroy

    End Sub
    Starter service:
    Code:
    #Region  Service Attributes
        
    #StartAtBoot: False
        
    #ExcludeFromLibrary: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Public Provider As FileProvider
    End Sub

    Sub Service_Create
        
    'This is the program entry point.
        'This is a good place to load resources that are not specific to a single activity.
        Provider.Initialize
        CallSubDelayed(FirebaseMessaging, 
    "SubscribeToTopics")
    End Sub

    Sub Service_Start (StartingIntent As Intent)
        

    End Sub

    Sub Service_TaskRemoved
        
    'This event will be raised when the user removes the app from the recent apps list.
    End Sub

    'Return true to allow the OS default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub

    Sub Service_Destroy

    End Sub

    Thanks in advance...
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Not sure why it happens. Are you sure that there isn't any other referenced library?

    If you like you can send me the project to erel@basic4ppc.com and I'll try it here.
     
  5. Almog

    Almog Active Member Licensed User

    OK, thank you very much, I will now send it.
    By the way, earlier I tried creating an example project, of using firebase notifications in it, and it didn't work, also.
    I will now send it...
     
  6. aeric

    aeric Active Member Licensed User

    Why you are using these 2 libraries?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Almog likes this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    This is fine. OkHttpUtils2 depends on OkHttp. It doesn't matter whether you add it yourself.
     
    Almog and aeric like this.
  9. Almog

    Almog Active Member Licensed User

  10. Almog

    Almog Active Member Licensed User

    I now tried it and it worked!:D
    Thank you very much for your help:)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice