得到" app:preDexDebug"添加特定jar时出错

时间:2015-04-09 18:45:07

标签: java android jar android-studio android-gradle

最近我试图使用android studio而不是eclipse,有一件事是我无法解决的。

当我尝试将以下类作为jar导入时,它会出现以下错误

班级:

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.ResourceId;
import com.google.api.services.youtube.model.SearchListResponse;
import com.google.api.services.youtube.model.SearchResult;

public class Search {
    private static final long NUMBER_OF_VIDEOS_RETURNED = 25;

    private static YouTube youtube;
    public static void main(String args[]){

    }
    public static HashMap<String, String> search(String queryTerm, String apiKey) {
        try {
            youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
                public void initialize(HttpRequest request) throws IOException {
                }
            }).setApplicationName("youtube-cmdline-search-sample").build();
            YouTube.Search.List search = youtube.search().list("id,snippet");
            search.setKey(apiKey);
            search.setQ(queryTerm);
            search.setType("video");
            search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
            search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED);

            SearchListResponse searchResponse = search.execute();
            List<SearchResult> searchResultList = searchResponse.getItems();
            if (searchResultList != null) {
                return prettyPrint(searchResultList.iterator(), queryTerm);
            }
        } catch (GoogleJsonResponseException e) {
            System.err.println("There was a service error: " + e.getDetails().getCode() + " : "
                    + e.getDetails().getMessage());
        } catch (IOException e) {
            System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage());
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return null;
    }

    private static HashMap<String, String> prettyPrint(Iterator<SearchResult> iteratorSearchResults, String query) {

        HashMap<String, String> m = new HashMap<String, String>();
        if (!iteratorSearchResults.hasNext()) {
            System.out.println(" There aren't any results for your query.");
        }

        while (iteratorSearchResults.hasNext()) {
            SearchResult singleVideo = iteratorSearchResults.next();
            ResourceId rId = singleVideo.getId();
            if (rId.getKind().equals("youtube#video")) {
                //Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().getDefault(); image url
                m.put(singleVideo.getSnippet().getTitle() ,rId.getVideoId());
            }
        }
        return m;
    }
}

错误:

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

堆栈追踪:

FAILURE: Build failed with an exception.

* What went wrong:          
Task 'compileDebug' is ambiguous in root project 'PROJECT_NAME'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidT
estAidl', 'compileDebugAndroidTestJava', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndr
oidTestSources', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTes
tJava', 'compileDebugUnitTestSources'.

* Try:                      
Run gradlew tasks to get a list of available tasks. Run with --info or --debug option to get more log output.

现在,我试图运行堆栈跟踪和调试,但没有任何东西向我展示这个特定的jar导致错误的原因。当我从lib文件夹和gradle中删除jar并导入其他jar时它们正常工作。

我尝试将jar导入到一个新项目中并将该项目导出到新jar中,但即便如此,它仍然会给我同样的错误

1 个答案:

答案 0 :(得分:0)

也许你的一些jar文件无法编译。检查您的gradle文件。您必须检查是否再次导入相同的JAR。确保您的AndroidManifest文件在清单节点中包含包名称。查看this answerthis以获取其他可能的解决方案。