Failed to build Android app (refer to both ActionBarSherlock & ViewPagerTabs) with Ant

11,093

Solution 1

I finally resolve it myself. I find that there's a android-support-v4.jar in ViewPagerTabs' libs folder. The solution is -- deleting this android-support-v4.jar, then make ViewPagerTabs depend on ActionBarSherlock (because ActionBarSherlock actually have one copy of Support Package).

I hope it's useful for people who wants to use ActionBarSherlock & ViewPagerTabs in one application and use Ant to built his/her application. Good luck.

Solution 2

You stated its because both library have android-support-v4.jar. See @porter-liu answer for non-maven builds.

For people using maven, set your ViewPager dependancy as:

    <dependency>
        <groupId>com.viewpagerindicator</groupId>
        <artifactId>library</artifactId>
        <version>2.4.1</version>
        <type>apklib</type>
        <exclusions>
            <exclusion>
                <groupId>com.google.android</groupId>
                <artifactId>support-v4</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

The exclusion tag stops the double import fixing the issue.

Share:
11,093
Porter Liu
Author by

Porter Liu

Updated on July 27, 2022

Comments

  • Porter Liu
    Porter Liu almost 2 years

    I have one Android app which uses ActionBarSherlock & ViewPagerTabs. I use Eclipse to write and build it, and it just works well until I try to build it with Ant. Here's what I did:

    1. go to ActionBarSherlock folder, run "android update lib-project --path ."
    2. go to ViewPagerTabs folder, run "android update lib-project --path ." too
    3. go to app folder, run "android update project --path ."
    4. run "and debug" under app folder, and I got following errors:

    :

    [javac] C:\Android\TestApp\src\com\test\App\TestActivity.java:46: cannot find symbol
    [javac] symbol  : method getSupportActionBar()
    [javac] location: class com.test.App.TestActivity
    [javac]         final ActionBar ab = getSupportActionBar();
    [javac]                              ^
    

    So question NO. 1: I have correct library references in app's project.properties, and ActionBarSherlock & ViewPagerTabs could be built successfully, why do I still get these errors?

    There's a workaround for this issue -- copy all classes.jar under library's bin folder into app's libs folder, and run "ant debug" again. But I need to delete these .jar files under app's libs folder after all .java files of app could be compiled.

    Running "ant debug" again after this, I will get following errors:

    [dx] processing archive C:\Android\ActionBarSherlock\library\bin\classes.jar...
    [dx] ignored resource META-INF/MANIFEST.MF
    [dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoStubImpl.class...
    [dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl.class...
    [dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat.class...
    [dx] processing android/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs.class...
    [dx] processing android/support/v4/app/ActionBar$LayoutParams.class...
    [dx] processing android/support/v4/app/ActionBar$OnMenuVisibilityListener.class...
    [dx] processing android/support/v4/app/ActionBar$OnNavigationListener.class...
    [dx] processing android/support/v4/app/ActionBar$Tab.class...
    [dx] processing android/support/v4/app/ActionBar$TabListener.class...
    [dx] processing android/support/v4/app/ActionBar.class...
    [dx] processing android/support/v4/app/ActivityCompatHoneycomb.class...
    [dx] 
    [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
    [dx] java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompatHoneycomb;
    [dx]    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    [dx]    at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
    [dx]    at com.android.dx.command.dexer.Main.processClass(Main.java:486)
    [dx]    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
    [dx]    at com.android.dx.command.dexer.Main.access$400(Main.java:67)
    [dx]    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
    [dx]    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
    [dx]    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
    [dx]    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
    [dx]    at com.android.dx.command.dexer.Main.processOne(Main.java:418)
    [dx]    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
    [dx]    at com.android.dx.command.dexer.Main.run(Main.java:206)
    [dx]    at com.android.dx.command.dexer.Main.main(Main.java:174)
    [dx]    at com.android.dx.command.Main.main(Main.java:95)
    [dx] 1 error; aborting
    

    My question NO.2 is: how can I fix this issue?

    Thanks!

  • Porter Liu
    Porter Liu about 12 years
    Alexander, thanks for the reply! I have built my app with Eclipse, so I have all the library references in the project.properties of my app. If I run "android update project --library ../pathToTheLibrary", the reduplicate library reference will be added into project.properties.
  • Damian
    Damian about 12 years
    Thanks! Didn't have this problem with my setup until I upgraded to ADTv17 but this fixed it.
  • Timmmm
    Timmmm over 11 years
    Note that you also have to make ActionBarSherlock export android-support (it's in the Project Structure->Modules dialog). I think you do anyway. It's acting kind of weird...
  • Timmmm
    Timmmm over 11 years
    And although it compiles fine, IntelliJ sprinkles loads of compile errors through the project. :-/
  • Timmmm
    Timmmm over 11 years
    Aha I found the problem: The order of the dependencies matters. You will have to have ActionBarSherlock before your app source.
  • IgorGanapolsky
    IgorGanapolsky almost 11 years
    Yes, it is usually a case of duplicate support-v4.jar files in included library projects.
  • Bharat Dodeja
    Bharat Dodeja almost 11 years
    @PorterLiu I am not using any library project instead I am using support-v4.jar and still getting same issue. I am working in Android Studio and fed up with this issue. Please help.