Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

android - How to change libs directory in Gradle?

I want to integrate Zbar into my application but cant seem to figure out how to accomplish this using the new Android Studio.

I have looked through the example and have copied over the code without any issues. The problem I am having is adding the libs to my project I cant seem to figure out how to do it. Could someone walk me through it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm not particularly familiar with IntelliJ or Gradle but I have figured it out. I used ZBarAndroidSDK-0.2.

  1. Copy the contents of the ZBar SDK libs/ folder into your project's libs/ folder.
  2. Modify your build.gradle (see below) to make sure the jar and native libs are included in your APK.
  3. To make IntelliJ aware of ZBar, add zbar.jar in your project structure. To do this, go to File > Project Structure > Libraries > + Sign > Java and find zbar.jar with the file picker. Add it to your project.

Add the following to your build.gradle (making sure to keep whatever other dependencies you've got):

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/zbar.jar')
}

task copyNativeLibs(type: Copy) {
    from(new File('libs')) { include '**' }
    into new File(buildDir, 'native-libs')
}

tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }

clean.dependsOn 'cleanCopyNativeLibs'

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniDir new File(buildDir, 'native-libs')
}

My build.gradle is based on this gist: https://gist.github.com/khernyo/4226923.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...