gpt4 book ai didi

java - 如何将 Android 支持 v7 库加载到 SBT Android 项目中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:57:32 25 4
gpt4 key购买 nike

我创建了一个 SBT 项目并使用 pfn/android-sdk-plugin 添加了一个 Android 模板我要做的就是创建一个测试应用程序来实现 recyclerview。 aar() 技术未找到依赖项。我的 build.sbt ...

import sbt.Keys._
import android.Keys._

android.Plugin.androidBuild

name := "firstsbt"

version := "1.0"

scalaVersion := "2.10.4"

javacOptions ++= Seq("-source", "1.7", "-target", "1.7")

scalacOptions in Compile ++= Seq("-deprecation","-feature","-language:implicitConversions","-unchecked")
unmanagedBase := baseDirectory.value / "libs"

// proguard help
proguardScala in Android := true
useProguard in Android := true

//set dependencies
libraryDependencies ++= Seq(
//aar("com.android.support" % "cardview-v7" % "21.0.3"),
//aar("com.android.support" % "appcompat-v7" % "23.1.1")
"com.android.support" % "appcompat-v7" % "23.1.1"
//"com.android.support" % "recyclerview-v7" % "23.1.1"
//"com.android.support" % "support-v4" % "r7" % "23.1.1"
//aar("com.android.support" % "recyclerview-v7" % "23.1.1")
//aar("com.github.chrisbanes.actionbarpulltorefresh" % "library" % "0.9.3")
//aar("net.simonvt.menudrawer" % "menudrawer" % "3.0.4"),
//"com.google.android" % "support-v4" % "r7",
//"io.spray" % "spray-json_2.10" % "1.2.6",
//"net.minidev" % "json-smart" % "1.2")
)
resolvers := Seq()

我已经尝试将 jars 放入非托管项目库中,它会编译和安装但会崩溃。

12-13 18:02:40.760    7217-7217/mobile.bt.app D/AndroidRuntime﹕ Shutting down VM
12-13 18:02:40.760 7217-7217/mobile.bt.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: mobile.bt.app, PID: 7217
java.lang.RuntimeException: Unable to start activity ComponentInfo{mobile.bt.app/mobile.bt.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2661)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at mobile.bt.app.MainActivity.onCreate(MainActivity.java:62)
at android.app.Activity.performCreate(Activity.java:6221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5835)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

当我取消对 arr 的注释时,我得到“找不到依赖项”请帮忙。

当我添加

libraryDependencies += "com.android.support" % "appcompat-v7"  % "23.1.1"

这是我刚刚加载 build.sbt 的最新日志

    [info] Loading global plugins from C:\Users\brandon\.sbt\0.13\plugins
[info] Loading project definition from C:\Users\brandon\IdeaProjects\firstsbt\project
[info] Set current project to firstsbt (in build file:/C:/Users/brandon/IdeaProjects/firstsbt/)
> [info] Defining *:shellPrompt
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to firstsbt (in build file:/C:/Users/brandon/IdeaProjects/firstsbt/)
[info] Defining *:artifactPath
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to firstsbt (in build file:/C:/Users/brandon/IdeaProjects/firstsbt/)
[info] Defining *:artifactClassifier
[info] The new value will be used by compile:packageBin::artifact, compile:packageDoc::artifact and 3 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to firstsbt (in build file:/C:/Users/brandon/IdeaProjects/firstsbt/)
[info] Applying State transformations org.jetbrains.sbt.ReadProject from C:/Users/brandon/.IntelliJIdea15/config/plugins/Scala/launcher/sbt-structure-0.13.jar
[info] Reading structure from C:\Users\brandon\IdeaProjects\firstsbt
[info] Updating {file:/C:/Users/brandon/IdeaProjects/firstsbt/}mobile-bt-app...
[info] Resolving com.android.support#appcompat-v7;23.1.1 ...
[info] Resolving com.android.support#appcompat-v7;23.1.1 ...
[warn] module not found: com.android.support#appcompat-v7;23.1.1
[warn] ==== local: tried
[warn] C:\Users\brandon\.ivy2\local\com.android.support\appcompat-v7\23.1.1\ivys\ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.pom
[info] Resolving org.scala-lang#scala-compiler;2.10.4 ...
[info] Resolving org.scala-lang#scala-library;2.10.4 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.4 ...
[info] Resolving org.scala-lang#jline;2.10.4 ...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.android.support#appcompat-v7;23.1.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] com.android.support:appcompat-v7:23.1.1 (C:\Users\brandon\IdeaProjects\firstsbt\build.sbt#L19-32)
[warn] +- firstsbt:firstsbt:1.0
[trace] Stack trace suppressed: run 'last *:update' for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: com.android.support#appcompat-v7;23.1.1: not found
sbt.ResolveException: unresolved dependency: com.android.support#appcompat-v7;23.1.1: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:291)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:188)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:165)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:132)
at sbt.IvySbt.sbt$IvySbt$$action$1(Ivy.scala:57)
at sbt.IvySbt$$anon$4.call(Ivy.scala:65)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at sbt.IvySbt.withDefaultLogger(Ivy.scala:65)
at sbt.IvySbt.withIvy(Ivy.scala:127)
at sbt.IvySbt.withIvy(Ivy.scala:124)
at sbt.IvySbt$Module.withModule(Ivy.scala:155)
at sbt.IvyActions$.updateEither(IvyActions.scala:165)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1369)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1365)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1399)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1397)
at sbt.Tracked$$anonfun$lastOutput$1.apply(Tracked.scala:37)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1402)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1396)
at sbt.Tracked$$anonfun$inputChanged$1.apply(Tracked.scala:60)
at sbt.Classpaths$.cachedUpdate(Defaults.scala:1419)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1348)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1310)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[error] sbt.ResolveException: unresolved dependency: com.android.support#appcompat-v7;23.1.1: not found
[error] Use 'last' for the full log.

最佳答案

libraryDependencies += "com.android.support" % "appcompat-v7"  % "23.1.1"

并且不要忘记在 SDK 管理器中安装 android 支持存储库

如果设置 resolvers := ()

,您也无法解析依赖关系

关于java - 如何将 Android 支持 v7 库加载到 SBT Android 项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com