I have two project A and B where B is added as a module of project A. I have added dependencies in A's Gradle build file. Now i can import B's class in A without any error (in editor) but can't build. Preferences is a class of project B.
Error:(22, 23) error: cannot find symbol class Preferences
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.0.0" defaultConfig { applicationId "com.example.A" minSdkVersion 9 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' compile project(':B') }
import org.apache.tools.ant.taskdefs.condition.Os apply plugin: "android-library" android { compileSdkVersion 18 buildToolsVersion "21.0.0" defaultConfig { minSdkVersion 9 targetSdkVersion 11 } buildTypes { release { minifyEnabled true proguardFiles 'proguard.cfg' } } sourceSets.main { jniLibs.srcDir 'src/main/jniLibs' jni.srcDirs = [] //disable automatic ndk-build call } task ndkBuild(type: Exec) { if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine 'ndk-build.cmd', '-C', file('src/main/jni').absolutePath } else { commandLine '/opt/adt-bundle-linux/android-ndk-r8e/ndk-build', '-C', file('src/main/jni').absolutePath } tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn ndkBuild } } } dependencies { compile 'com.android.support:support-v4:18.0.0' }
I can successfully build the project(A) if remove the import.
Output. In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.
The “cannot find symbol” error comes up mainly when we try to use a variable that's not defined or declared in our program. When our code compiles, the compiler needs to verify all the identifiers we have. The error “cannot find symbol” means we're referring to something that the compiler doesn't know about.
It can happen if the library (be it a local module or external dependency) has a minifyEnabled true
, but library's ProGuard configuration is missing or not correct (the class is eligible for removing by ProGuard). This leads to class not being compiled.
For me it was a similar problem but on proguard conf. proguard was active on a first library and inactive on a second.
Copie same proguard conf on all build.gradle has solved the "cannot find symbol class" error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With