最近想做個app,里面需要有一個二維碼掃描的功能,然后谷歌之后發現Zxing這個用的人好多,就看看怎么用;
然后就在github上拉下他們的源碼,導入eclipse,然后編譯之后導出為jar文件【用的android studio做安卓的,不過不知道怎么導出……】
然后將導出好的jar文件導入android studio 的時候問題來了,每次編譯后都在報錯:
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
好吧說明已經很清楚了,某個地方需要加兩句話,可以不明白到底要在哪里加啊;於是經歷了各種千辛萬苦(百度,谷歌,QQ群……)耗時一天半,終於搞定了;
下面是解決辦法
1.首先在github上拉取源碼后,在eclipse里面打包的時候需要給要打包的文件目錄下面加一個文件 build.gradle 然后里面的內容就是:
apply plugin: 'java' sourceCompatibility = 1.7 targetCompatibility = 1.7 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
2.然后eclipse打包的時候請在build path那里指定jdk版本為1.7
3.將新打包好的jar包導入android studio中,然后jar包上右擊,選擇 as a library,debug運行成功!!!
最終文件的目錄結構是這樣的: build.gradle 中的內容就是第一步中的內容

