How to import this library to Android Studio

2019-08-12 07:09发布

问题:

How can I import widgets library in this github link to my project??? https://github.com/tobykurien/BatteryFu

I tried a way but faced with this error while run :

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 2

回答1:

Please follow below steps :

  1. Click on File -> New -> Import New Module.
  2. Add Souce Directory path as library root level path.
  3. Click 'OK' and 'Finish'.
  4. Go to project setting -> Widget -> dependencies -> click in '+' -> add module ->add widget here.
  5. Now open Widget module libs folder and remove your support-v4 jar file.
  6. Remove 'compile fileTree(dir: 'libs', include: ['*.jar'])' from Widget gradle file.
  7. Go to project setting -> Widget -> dependencies -> click in '+' -> add library ->add support v4 here.
  8. Open Manifest.xml of widget module.
  9. Change minSDk to '4'

Now build your project and run.And if you found any error let me know.

Your Widget gradle file should look like :

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}
apply plugin: 'android-library'
android {
    compileSdkVersion 18
    buildToolsVersion "19.1"

    dependencies {

    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            aidl.srcDirs = ['src']
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
}

Manifest.xml of Widget should look like :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.koushikdutta.widgets"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true">
    </application>

</manifest>