Error: Cannot Find Symbol Class R

Discussion in 'Technical Discussion' started by Bryan Allan Talisay, Jan 21, 2019.

  1. Bryan Allan Talisay

    Bryan Allan Talisay Boxer

    Joined:
    Dec 5, 2018
    Messages:
    15
    Likes Received:
    0
    hello buildbox,

    Is anyone experiences this error??
    Im integrating firebase sdk. Thank you errorR.png
     
  2. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    Yes! I'm seeing the same error!
    I've set up Game Services for my game to use Leaderboards and wanted to Implement Firebase. I did include the google-services.json file and dependencies on my gradle files. However I'm getting the same error "error: cannot find symbol class R" when trying to make the Build. I already tried doing a "Clean Project", "Rebuild Project", "Sync Project with gradle file" and clearing Caches, but it doesn't help. My Android studio knowledge is limited.
     
  3. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    OK. It has been a long time since I have used Android Studio. I quit developing for Google some time ago, but the issue you are referring to I seem to remember running into in the past.
    Here is what I remember about that Error. First, that error, Can not find symbol class R, can be caused by a whole lot of monsters. So, if you have already tried
    1. Clean Project
    2. Rebuild Project\Sync Project
    3. Invalidate cache (not just clear, invalidate it)
    Then restart Android Studio and load. If that does not fix it then check your XML files, culprit is many times there.

    But the easiest fix after doing the above steps 1 through 3 is to now change your min sdk level, if I remember right, Google Play Services require a minimum sdk level great then 7, so set yours to 8. this needs changed in the manifest file and in the build.gradle file. Then rebuild project.

    Another thing to try is change your latest sdk version, click File then Project Structure. Select "app" , under Properties you can change your Compile SDK version, also there is a parameter called Build Tools Version, sometimes changing that helps as well.

    Recalling all of this from memory and to be honest I do not recall what version of Android Studio I was even using back then. But hopefully it helps you!
     
    itzonator likes this.
  4. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    Thank you Codifie for a quick help!
    I'm still struggling with this error. I did try clean, rebuild, invalidate cache and restarting Android Studio.
    I have my min SDK version set to 16 (Android 4.1) and target SDK to 26 (Android 8.0) in my App gradle file (It's not necessary to include it anymore in the manifest as far as I know).
    I've checked my XML files but find nothing suspicious there. I only have the main.xml file and my network_security_config.xml file for Heyzap integration.
    I hope I can find a solution soon, I'm almost ready to lunch my first game :)
     
  5. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    Ok.
    Did you check your Build Tools Version?
    Also, the below line is an example, what does this line say in your build.gradle?
    dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    ...
     
  6. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    For my Build Tools Version I'm running 28.0.3 and in my dependencies I have set it to 3.3.1 "com.android.tools.build:gradle:3.3.1"
     
  7. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    Thats perfect, you are good there,
    Ok, have you tried to
    import rootpackage.R;
     
  8. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    Also, I do know that downgrading to 3.2.1 for your Gradle Build Tools does some times fix this problem.
     
  9. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    I tried using import com.company.game.R; and get an error on Build.
    "Program type already present: com.google.android.gms.location.places.zza"

    I'm also using version 3.1.3 for my Gradle Build Tools. This was the version I was using before and I was able to make my game work. Now I cannot get my game working anymore. I'm not even calling the Firebase sdk. I don't know if it has anything to do with updating my Android Studio version.
     
  10. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    I've reverted back to Android Studio 3.2 and run things as before.
    I'm not calling Firebase at all and I get the same error. It appears there's a conflict with how libraries are called. I'm using Heyzap and implementing libraries as follow:
    Code:
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // Heyzap //
    implementation 'com.google.android.gms:play-services-ads:11.+'
    implementation 'com.google.android.gms:play-services-location:11.+'
    implementation 'com.fyber:fairbid:9.53.0'
    Whenever I change imports that use the "+" to a specific version I get the error "error: cannot find symbol class R" in my PTServicesBridge.java file:

    For exampe if I change this:
    Code:
    implementation 'com.google.android.gms:play-services-ads:11.+'
    to this:
    Code:
    implementation 'com.google.android.gms:play-services-ads:17.1.3'
    I'm also getting a warning I wasn't seeing before "Uses unchecked or unsafe operations" on my Cocos2dxReflectionHelper.java file.
     
    Last edited: Feb 27, 2019
  11. maxcar

    maxcar Boxer

    Joined:
    Sep 27, 2018
    Messages:
    23
    Likes Received:
    4
    Finally got it working! Hope this helps. I'm also using Game Analytics and Heyzap.
    I'm using "12.+" for Firebase implementation and that seems to be working.

    Here's my gradle Project setup
    Code:
    buildscript {
        repositories {
            jcenter()
            google()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
            // Firebase: google-services plugin
            classpath 'com.google.gms:google-services:4.2.0'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
            maven {
                url  "https://fyber.bintray.com/fairbid-maven"
            }
            maven {
                url 'http://maven.gameanalytics.com/release'
            }
        }
    }
    
    And here's my gradle Module setup
    Code:
    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 28
        buildToolsVersion "28.0.3"
    
        defaultConfig {
            applicationId "com.company.game"
            minSdkVersion 16
            targetSdkVersion 28
            multiDexEnabled true
    
            ndk {
                moduleName "player_shared"
            }
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    
        dexOptions {
            javaMaxHeapSize "4g"
        }
    }
    
    dependencies {
        implementation 'com.google.android.gms:play-services:12.0.1'
        implementation 'com.android.support:multidex:1.0.3'
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        // Fyber //
        implementation 'com.google.android.gms:play-services-ads:12.+'
        implementation 'com.google.android.gms:play-services-location:12.+'
        implementation 'com.fyber:fairbid:9.53.0'
        // GameAnalytics //
        implementation 'com.gameanalytics.sdk:gameanalytics-android:3.4.2'
        // Firebase
        implementation 'com.google.firebase:firebase-core:12.+'
    }
    
    // Firebase
    apply plugin: 'com.google.gms.google-services'
     
    Alex809 likes this.
  12. Alex809

    Alex809 Boxer

    Joined:
    Apr 29, 2019
    Messages:
    9
    Likes Received:
    1
    Thank you dude. Was having the same problem!
     
  13. itzonator

    itzonator Serious Boxer

    Joined:
    Dec 18, 2017
    Messages:
    595
    Likes Received:
    230
    Hmm.. resolved this by removing this line with .R issue:
    import com.google.android.gms.R from PTServicesBridge.java
     
  14. UNLEFT

    UNLEFT Boxer

    Joined:
    Jan 2, 2021
    Messages:
    5
    Likes Received:
    0
    Can Anybody provide me a PTServicesBridge.java file because I am getting a lot of error for this section in my buildbox project. For this section I can not give ads in my game.
    Please provide me the file for buildbox 2 and my version of buildbox is 2.3.3
     
  15. Josh (Nology Games)

    Josh (Nology Games) Avid Boxer

    Joined:
    Nov 27, 2017
    Messages:
    200
    Likes Received:
    155
    if you upgrade to the latest version of Buildbox 2, you will have these issues fixed for you
     
  16. UNLEFT

    UNLEFT Boxer

    Joined:
    Jan 2, 2021
    Messages:
    5
    Likes Received:
    0
    I need that file PTServicesBridge.java because when I want to monetize my game with appodeal an error occurred the error occurred only and only when I add this line in my defendecy

    implementation ('com.appodeal.ads:sdk:2.6.3.+') {
    exclude group: 'com.appodeal.ads.sdk.networks', module: 'smaato'
    }
    The error is ( Duplicate class com.google.android.gms.location.places.zza found in modules jetified-play-services-places-12.0.1-runtime.jar (com.google.android.gms:play-services-places:12.0.1) and play-services-places-placereport-16.0.0-runtime.jar (com.google.android.gms:play-services-places-placereport:16.0.0) )
    And my defendecy is

    defendecy{
    Implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.android.support:multidex:1.0.3'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    }
    For this defencdecy section I can not show ads in my game. When I want modify my defendecy section the error occurred in PTServicesBridge.java. So I need a
    PTServicesBridge.java file to fix all of it.
     

Share This Page