0

I'm using Android Studio 0.8.9

Recently, I in the process of migrating Eclipse project into Android studio project. I begun with File -> Import Project...

I encounter a very strange problem, where Android studio unable to compile my main project, due to cannot find symbol. Those symbols suppose to found in one of my library projects : https://code.google.com/p/android-lockpattern/ (version 3.0.1)

These is one of the error messages

C:\projects\xxx.java:4: error: cannot find symbol 
import group.pals.android.lib.ui.lockpattern.prefs.DisplayPrefs;

These are my strange observation

I can confirm no error while building androidlockpattern

:androidlockpattern:compileLint
:androidlockpattern:copyReleaseLint UP-TO-DATE
:androidlockpattern:preBuild
:androidlockpattern:preReleaseBuild
:androidlockpattern:checkReleaseManifest
:androidlockpattern:preDebugBuild
:androidlockpattern:preDebugTestBuild
:androidlockpattern:prepareComActionbarsherlockActionbarsherlock440Library UP-TO-DATE
:androidlockpattern:prepareReleaseDependencies
:androidlockpattern:compileReleaseAidl UP-TO-DATE
:androidlockpattern:compileReleaseRenderscript UP-TO-DATE
:androidlockpattern:generateReleaseBuildConfig UP-TO-DATE
:androidlockpattern:generateReleaseAssets UP-TO-DATE
:androidlockpattern:mergeReleaseAssets UP-TO-DATE
:androidlockpattern:generateReleaseResValues UP-TO-DATE
:androidlockpattern:generateReleaseResources UP-TO-DATE
:androidlockpattern:mergeReleaseResources UP-TO-DATE
:androidlockpattern:processReleaseManifest UP-TO-DATE
:androidlockpattern:processReleaseResources UP-TO-DATE
:androidlockpattern:generateReleaseSources UP-TO-DATE
:androidlockpattern:compileReleaseJava UP-TO-DATE
:androidlockpattern:proguardRelease UP-TO-DATE
:androidlockpattern:mergeReleaseProguardFiles UP-TO-DATE
:androidlockpattern:compileReleaseNdk UP-TO-DATE
:androidlockpattern:packageReleaseJniLibs UP-TO-DATE
:androidlockpattern:packageReleaseRenderscript UP-TO-DATE
:androidlockpattern:packageReleaseResources UP-TO-DATE
:androidlockpattern:bundleRelease

My main project does include androidlockpattern as module

dependencies {
    compile project(':androidlockpattern')
    ...

Android studio editor can recognize androidlockpattern. No red line highlighted

enter image description here

I have other library projects. They all compiled together well with my main project. The only error so far is androidlockpattern.

Here's are the detailed error message

C:\projects\xxx.java:4: error: cannot find symbol
import group.pals.android.lib.ui.lockpattern.prefs.DisplayPrefs;
                                                  ^
  symbol:   class DisplayPrefs
  location: package group.pals.android.lib.ui.lockpattern.prefs
C:\projects\xxx.java:195: error: cannot find symbol
            Intent intent = new Intent(LockPatternActivity.ACTION_COMPARE_PATTERN, null,
                                                          ^
  symbol:   variable ACTION_COMPARE_PATTERN
  location: class LockPatternActivity
C:\projects\xxx.java:198: error: cannot find symbol
            DisplayPrefs.setMaxRetry(this, Integer.MAX_VALUE);
            ^
  symbol:   variable DisplayPrefs
  location: class JStockFragmentActivity
C:\projects\xxx.java:199: error: cannot find symbol
            intent.putExtra(LockPatternActivity.EXTRA_PATTERN, startupLockPattern);
                                               ^
  symbol:   variable EXTRA_PATTERN
  location: class LockPatternActivity
C:\projects\xxx.java:1239: error: cannot find symbol
            case LockPatternActivity.RESULT_FAILED:

For build.gradle of androidlockpattern, it looks like the following

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "group.pals.android.lib.ui.lockpattern"
        minSdkVersion 10
        targetSdkVersion 10
    }

    buildTypes {
        release {
            runProguard true
            proguardFiles 'proguard.cfg'
        }
    }
}

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:19.1.0'
}

Here's my project settings. Seems fine to me.

enter image description here

Any idea what other steps I can take, to diagnostic the root cause?

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

2 Answers2

1
  • Remove your library, delete them from the project.
  • Copy it to "app"/libraries/
  • Go on File -> Import Module, select the library inside libraries folder.
  • Add line -> compile project(':your_library_folder_name') to build.gradle.
  • Sync gradle.
  • Build project.
Marckaraujo
  • 7,422
  • 11
  • 59
  • 97
1

Acording to Android docs:

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.

Change runProguard true to runProguard false

If you want to run Proguard on your project you should change the proguard.cfg accordingly.

This bug may also apply to you: https://code.google.com/p/android/issues/detail?id=52962

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • Thanks. I don't know what Android Studio chooses to turn on proguard for project library, imported directly from Eclipse. It seems that, project library shouldn't turn on proguard : http://stackoverflow.com/questions/15166380/setting-up-proguard-with-android-library-projects – Cheok Yan Cheng Oct 31 '14 at 02:03
  • This is another answer, regarding whether to run proguard for library project. The answer is from proguard author himself :) - http://stackoverflow.com/questions/10982344/is-proguard-cfg-needed-for-library-projects?lq=1 – Cheok Yan Cheng Oct 31 '14 at 02:05