2016-03-15 72 views
0

我想在我的Android項目中使用這個realtime-android項目作爲庫,但是當我嘗試導入這個項目時,它給了我這個「找不到可導入的項目」。不能使用realtime-android庫

那麼如何使用它作爲一個庫? 謝謝你的幫助。 這個的build.gradle:

apply plugin: 'android' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':appcompat_v7') 
    compile project(':gridlayout_v7') 
    compile 'com.goodow.realtime:realtime-android:0.5.0' 
} 

android { 
    compileSdkVersion 20 
    buildToolsVersion "20.0.0" 

    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 

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

     // Move the tests to tests/java, tests/res, etc... 
     instrumentTest.setRoot('tests') 

     // Move the build types to build-types/<type> 
     // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 
     // This moves them out of them default location under src/<type>/... which would 
     // conflict with src/ being used by the main source set. 
     // Adding new build types or product flavors should be accompanied 
     // by a similar customization. 
     debug.setRoot('build-types/debug') 
     release.setRoot('build-types/release') 
    } 
} 
+0

你使用Gradle,還是你下載它作爲JAR? –

+0

我已經從github上下載了這個項目,但是我無法將它導入到我的工作空間中,將它作爲庫添加到我當前的項目中。 – SDH

+0

爲什麼你需要從Github下載項目? –

回答

0

按照Maven Repo,你可以將其包含在你的build.gradle依賴部分。

我注意到您錯過了repositories部分,因此您可能需要添加該部分。例如,這是我的build.gradle。

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.5.0' 
    } 
} 

apply plugin: 'com.android.application' 

repositories { 
    jcenter() 
} 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    // ... other stuff 

} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile "com.android.support:appcompat-v7:23.2.1" 
    compile "com.android.support:design:23.2.1" 

    // this line 
    compile 'com.goodow.realtime:realtime-android:0.5.0' 

} 

或者你可以使用下載JAR按鈕,把它放到你的項目的libs/文件夾。

+0

我在build.gradle中包含了這一行,然後我應該怎麼做才能使它工作?我已經將項目放入libs /中,但導入仍然無法解析。 – SDH

+0

您只需要使用gradle **或**下載JAR,而不是兩者。我會推薦gradle。另外,你想要導入什麼?我可以做'import com.goodow.realtime.android.AndroidPlatform;'就好了,沒有錯誤。 –

+0

我添加了該行,然後清理項目,但導入仍然無法解析。我試圖導入com.goodow.realtime.android.AndroidPlatform。 – SDH