These are chat archives for scala-android/sbt-android

18th
Aug 2016
Rafal Wachol
@charafau
Aug 18 2016 04:21
http://ij.bazel.io/ - seems like plugin for intellij is there
jhegedus42
@jhegedus42
Aug 18 2016 10:55
what does the proguard cache cache ?
"The bigger your cache, the higher the chance that a code change in your project now calls a method that has previously been removed by ProGuard and is therefore not included in the cache. That is a so called cache miss."
can someone explain me what proguard cache does ? like I was a 5 year old ?
1) scala compiler generates jar files
2) then proguard removes unnecessary stuff from it
3) dex is generated from the remaining
jhegedus42
@jhegedus42
Aug 18 2016 11:01
where does proguard cache come in , in this picture ?
"Large, multi-megabyte libraries should always be cached to avoid hitting the dex-file method-limit." how does proguard cache influence the resulting dex method count ?
@Taig ^ ?
jhegedus42
@jhegedus42
Aug 18 2016 11:19
from here : scala-android/sbt-android#200
This message was deleted

How proguard cache works:

Run proguard, take everything that prefix matches the rules in
proguardCache and store them in proguard-cache.jar

Everything else is not minimized by proguard.

On a cache hit, take proguard-cache.jar and the remaining jars and pass
directly to dex.

Therefore, as a result, dex method counts for a proguard cache hit must
always be higher than a full proguard run.

To fix running out of methods in a cache hit, take the highest offending
packages and add them to proguardCache.

so for example if I have proguardCache ++= "org.scalatest" :: "org.scalactic" :: "org.sqldroid" :: "slick" :: "com.typesafe.slick"::Nil
jhegedus42
@jhegedus42
Aug 18 2016 11:26
then all this stuff is in proguard-cache.jar ?
what i don't get, what is a cache hit/ miss ?
Niklas Klein
@Taig
Aug 18 2016 12:00
ProGuard removes code not only from your codebase, but also of your dependencies. So, let's assume you have a JSON library in your build (and added it to the proguardCache), but all you ever do in your code is decoding JSON that you receive from an API, but never encoding. ProGuard will see that and remove all the code related to encoding, since you are not using that (assuming that the library has no internal cross dependencies between en- and decoding). The manipulated JSON library is now in your cache and won't be ProGuarded again next time you build which will save you quite some time. Now you keep developing features for your app. You decode yet another JSON response and enter compile: cache hit. All the code you need for that is already in your cache. Now you find yourself in a situation where you need to respond to the API with JSON data. In order to do that you need to encode a case class with the JSON library. You enter compile, but you'll face a cache miss obviously, because the code for encoding got stripped out already. This means the ProGuard cache has to be rebuilt now.
The consequence is that while you are actively developing with ProGuard, you should -keep everything that you are frequently working / experimenting with.
But it general it's easier to develop with MultiDex, not using ProGuard. And if your app size permits, disable MultiDex for release builds, but use ProGuard instead. But even if you use MultiDex for release builds, you should still ProGuard it. Always ProGuard release builds.
Niklas Klein
@Taig
Aug 18 2016 12:09
If you set your minSdkVersion to 21 you can make use of incremental MultiDex which is rather fast. That is how I develop most of the time. Even though the actual minSdkVersion of my app is 15. But building / recompiling is a pain then because it takes so much longer. So I only develop / test for < 21 devices when necessary / specific problems arise.
jhegedus42
@jhegedus42
Aug 18 2016 12:21
Cool!
Thanks @Taig !
so basically multidex is the way to go
Niklas Klein
@Taig
Aug 18 2016 12:24
Imho, yes. But beware. If you use it for release builds <21, you'll have to deal with the MultiDex configuration, which isn't necessarily more fun than configuring ProGuard ;)
jhegedus42
@jhegedus42
Aug 18 2016 12:41
hmm.... but onwards 21 its ok ?
i give it a try !
thanks for the tip !
Niklas Klein
@Taig
Aug 18 2016 12:47
Yes, because 21 comes with ART and native multidex support. Older versions need multidex support library with additional configuration. Also the older versions do not support incremental multidex builds and are therefore painfully slow.
But then again you'll run into problems with instrumentation tests + multidex ;)
jhegedus42
@jhegedus42
Aug 18 2016 12:54
hmmm
so multidex does not work with instrumentation tests ?
even after 21 ?
But I gave up on it
Perry
@pfn
Aug 18 2016 13:16
testing sucks no one does it
anyway, just use proguard cache, problem solved for the most part
jhegedus42
@jhegedus42
Aug 18 2016 13:26
ok, good to know, so you are not doing any instrumentation tests ? @Taig
what do people do instead of testing ?
i wanna test db layer
what to use if not instrumentation tests for it ?
Niklas Klein
@Taig
Aug 18 2016 13:30
unit tests
Perry
@pfn
Aug 18 2016 13:31
if you want to experiment, protify
testing isn't for experimenting
jhegedus42
@jhegedus42
Aug 18 2016 13:31
hmmm
yeah
that kinda makes sense
Perry
@pfn
Aug 18 2016 13:32
use a tool that is optimized for exploration
jhegedus42
@jhegedus42
Aug 18 2016 13:32
yeah, exploration is what i am mainly doing
Perry
@pfn
Aug 18 2016 13:47
instrumentation tests work, but they're for testing, and they're not meant to be fast
jhegedus42
@jhegedus42
Aug 18 2016 13:54
yeah... i need to look into this protify....
Perry
@pfn
Aug 18 2016 14:06
nothing to look into, add a plugin and add settings
jhegedus42
@jhegedus42
Aug 18 2016 14:26
ok.... sounds simple :)
Perry
@pfn
Aug 18 2016 14:36
it is simple
Rafal Wachol
@charafau
Aug 18 2016 16:47

@pfn how did you setup opencv with sbt? I project with two subproejcts app and openCVLibrary310:

name := "OpenCvScala"
organization := "com.nullpointerbay.opencvscala"
version := "0.0.1"
versionCode := Some(1)

val sharedSettings = Seq(
    platformTarget := "android-23",
    minSdkVersion in Android := "21",
    showSdkProgress in Android := false,
    scalaVersion := "2.11.8",
    scalacOptions ++= Seq("-feature", "-Xexperimental" ,"-language:implicitConversions", "-language:postfixOps", "-target:jvm-1.7"),
    javacOptions in Compile ++= "-source" :: "1.7" :: "-target" :: "1.7" :: Nil
   )

val openCVLibrary310 = project.settings(androidBuildAar:_*)
  .settings(sharedSettings: _*)
  .settings(libraryProject := true)

val app = project.androidBuildWith(openCVLibrary310)
  .settings(sharedSettings: _*)
  .settings(libraryProject := false)

resolvers ++= Seq(
  Resolver.mavenLocal,
  Resolver.sonatypeRepo("releases"),
  "jcenter" at "http://jcenter.bintray.com"
)

useProguard in Android := false
useProguardInDebug in Android := (useProguard in Android).value
dexMulti in Android := true
dexMaxHeap in Android := "2048M"

but when I run this I get

[error] This project cannot dex, it has set 'libraryProject := true'
[error] (openCVLibrary310/android:dexMainClassesConfig) This project cannot dex, it has set 'libraryProject := true'
[error] Total time: 2 s, completed Aug 19, 2016 1:41:45 AM

but it has to be libraryProject so... I'm a little bit confused ;)

Rafal Wachol
@charafau
Aug 18 2016 17:09
ok I got it through
now I cannot load jni lib :(
jhegedus42
@jhegedus42
Aug 18 2016 17:13
is this good if I don't wanna bother with SQL ? https://github.com/Taig/soap
Rafal Wachol
@charafau
Aug 18 2016 17:15
I dont know how it eliminates sql ?
jhegedus42
@jhegedus42
Aug 18 2016 17:16
well, just saving data to file
anyone using ormlite ? for persistence ?
slick does not seem to work well
running into problems
Perry
@pfn
Aug 18 2016 17:19
@charafau use javacv, not opencv directly
Perry
@pfn
Aug 18 2016 17:20
@charafau and for that matter, app/android:run
@charafau run in wrong project tries to aggregate
Rafal Wachol
@charafau
Aug 18 2016 17:22
@pfn yes I've solved that (run project)
but now, opencv has official bindings so there's no point in javacv
pfn @pfn shrugs
Perry
@pfn
Aug 18 2016 17:22
the build setup sucks
javacv > opencv
jhegedus42
@jhegedus42
Aug 18 2016 17:23
does Ormlite work with Scala ?
Rafal Wachol
@charafau
Aug 18 2016 17:23
try ;)
jhegedus42
@jhegedus42
Aug 18 2016 17:23
yeah
Rafal Wachol
@charafau
Aug 18 2016 17:23
@pfn I also want to try to setup jni so I only want to package jni libs together with apk
jhegedus42
@jhegedus42
Aug 18 2016 17:23
what do folks here use for persistence ?
I know @pfn writes sql by hand.
Rafal Wachol
@charafau
Aug 18 2016 17:24
for now that's the best thing you can do
jhegedus42
@jhegedus42
Aug 18 2016 17:24
hmm
Rafal Wachol
@charafau
Aug 18 2016 17:24
but that's the same with normal android
jhegedus42
@jhegedus42
Aug 18 2016 17:24
interesting
Perry
@pfn
Aug 18 2016 17:25
@charafau that happens automatically
Rafal Wachol
@charafau
Aug 18 2016 17:25
it would be the best to get some scala's framework and port it to android (without all heavy dependencies and jdbc)

@pfn

08-19 02:26:02.089  3028  3028 D OpenCV/StaticHelper: First attempt to load libs
08-19 02:26:02.089  3028  3028 D OpenCV/StaticHelper: Trying to init OpenCV libs
08-19 02:26:02.089  3028  3028 D OpenCV/StaticHelper: Trying to load library opencv_java3
08-19 02:26:02.090  3028  3028 D OpenCV/StaticHelper: Cannot load library "opencv_java3"

seems like I dont have it

Perry
@pfn
Aug 18 2016 17:26
@charafau then the libraries are in the wrong location?
@charafau paste dirtree
they should be in openCVLibrary310/src/main/jniLibs/...
Rafal Wachol
@charafau
Aug 18 2016 17:27
.
├── aa.txt
├── app
│   ├── src
│   │   ├── androidTest
│   │   │   └── java
│   │   │       └── com
│   │   │           └── nullpointerbay
│   │   │               └── opencvscala
│   │   │                   └── MainActivityTest.java
│   │   ├── jni
│   │   │   ├── arm64-v8a
│   │   │   │   ├── libopencv_calib3d.a
│   │   │   │   ├── libopencv_core.a
│   │   │   │   ├── libopencv_features2d.a
│   │   │   │   ├── libopencv_flann.a
│   │   │   │   ├── libopencv_highgui.a
│   │   │   │   ├── libopencv_imgcodecs.a
│   │   │   │   ├── libopencv_imgproc.a
│   │   │   │   ├── libopencv_java3.so
this is my project structure
Perry
@pfn
Aug 18 2016 17:27
that's wrong then
Rafal Wachol
@charafau
Aug 18 2016 17:28
ok, I will try
Perry
@pfn
Aug 18 2016 17:28
src/main/jniLibs
Rafal Wachol
@charafau
Aug 18 2016 17:28
in app or opencvlibrary310 ?
Perry
@pfn
Aug 18 2016 17:28
if you're looking to ship a library with everything self-contained, then opencvlibrary310
Rafal Wachol
@charafau
Aug 18 2016 17:31
either doesnt work but I might try with this:
08-19 02:30:34.167  3569  3569 I art     : Late-enabling -Xcheck:jni
08-19 02:30:34.196  3569  3576 E art     : Failed sending reply to debugger: Broken pipe
08-19 02:30:34.196  3569  3576 I art     : Debugger is no longer active
08-19 02:30:34.196  3569  3576 I art     : Starting a blocking GC Instrumentation
08-19 02:30:34.224  3569  3569 W System  : ClassLoader referenced unknown path: /data/app/com.nullpointerbay.opencvscala-2/lib/arm
08-19 02:30:34.273  3569  3569 D OpenCV/StaticHelper: Trying to get library list
08-19 02:30:34.274  3569  3569 E OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
08-19 02:30:34.274  3569  3569 D OpenCV/StaticHelper: Library list: ""
08-19 02:30:34.274  3569  3569 D OpenCV/StaticHelper: First attempt to load libs
08-19 02:30:34.274  3569  3569 D OpenCV/StaticHelper: Trying to init OpenCV libs
08-19 02:30:34.274  3569  3569 D OpenCV/StaticHelper: Trying to load library opencv_java3
08-19 02:30:34.274  3569  3569 D OpenCV/StaticHelper: Cannot load library "opencv_java3"
08-19 02:30:34.274  3569  3569 W System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.nullpointerbay.opencvscala-2/base.apk"],nativeLibraryDirectories=[/data/app/com.nullpointerbay.opencvscala-2/lib/arm, /system/lib, /vendor/lib]]] couldn't find "libopencv_java3.so"
08-19 02:30:34.275  3569  3569 W System.err:       at java.lang.Runtime.loadLibrary0(Runtime.java:972)
08-19 02:30:34.275  3569  3569 W System.err:       at java.lang.System.loadLibrary(System.java:1530)
08-19 02:30:34.275  3569  3569 W System.err:       at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
08-19 02:30:34.275  3569  3569 W System.err:       at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
08-19 02:30:34.275  3569  3569 W System.err:       at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
08-19 02:30:34.275  3569  3569 W System.err:       at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:77)
08-19 02:30:34.275  3569  3569 W System.err:       at com.nullpointerbay.opencvscala.MainActivity$.load(sample.scala:26)
08-19 02:30:34.275  3569  3569 W System.err:       at com.nullpointerbay.opencvscala.MainActivity.onCreate(sample.scala:16)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.Activity.performCreate(Activity.java:6664)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.ActivityThread.-wrap12(ActivityThread.java)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
08-19 02:30:34.275  3569  3569 W System.err:       at android.os.Handler.dispatchMessage(Handler.java:102)
08-19 02:30:34.275  3569  3569 W System.err:       at android.os.Looper.loop(Looper.java:154)
08-19 02:30:34.275  3569  3569 W System.err:       at android.app.ActivityThread.main(ActivityThread.java:6077)
08-19 02:30:34.276  3569  3569 W System.err:       at java.lang.reflect.Method.invoke(Native Method)
08-19 02:30:34.276  3569  3569 W System.err:       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
08-19 02:30:34.276  3569  3569 W System.err:       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
class loader is wrong
Perry
@pfn
Aug 18 2016 17:31
clean build
Rafal Wachol
@charafau
Aug 18 2016 17:32
I did
Perry
@pfn
Aug 18 2016 17:32
ls app/target/android/intermediates/ndk/jni
er, app/target/android/intermediates/ndk/collect-jni
and for that matter, are you running in 64bit mode?
Rafal Wachol
@charafau
Aug 18 2016 17:33
it's empty
Perry
@pfn
Aug 18 2016 17:33
you only have 64bit libs
then you didn't put them into src/main/jniLibs/...
Rafal Wachol
@charafau
Aug 18 2016 17:33
no, no i have all libs (just pasted one dir)
Perry
@pfn
Aug 18 2016 17:33
oh, I'm sorry, src/main/libs
not src/main/jniLibs
Rafal Wachol
@charafau
Aug 18 2016 17:35
yes now it works :)
and apk is bigger
thank you
Perry
@pfn
Aug 18 2016 17:38
package iota.sample

import android.app.Activity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.graphics.drawable.Animatable
import iota._
import android.widget._
import android.view.ViewGroup.LayoutParams._
import android.view.Gravity

class MainActivity extends AppCompatActivity { self =>
    // allows accessing `.value` on TR.resource.constants
    implicit val context = this

    lazy val views = ViewTree.inflate(this, Main)
    case class Main(
        container: LinearLayout,
        text: TextView, image: ImageView
    ) extends ViewTree[LinearLayout] {
        container.setOrientation(LinearLayout.VERTICAL)
        text.lp(MATCH_PARENT, WRAP_CONTENT)
        text.setText(s"Hello world, from ${TR.string.app_name.value}")
        text.setTextAppearance(self, android.R.style.TextAppearance_Large)
        image.lp(MATCH_PARENT, 256.dp, Gravity.CENTER)
        image.setImageResource(R.drawable.waving_scala_android)
    }
    override def onCreate(savedInstanceState: Bundle): Unit = {
        super.onCreate(savedInstanceState)
        setContentView(views.container)
        views.image.getDrawable match {
          case a: Animatable => a.start()
          case _ => // not animatable
        }
    }
}
sample of the layout dsl
same as the generated hello world, but minus xml layout
Perry
@pfn
Aug 18 2016 17:53
@jhegedus42 @aafa uses realm successfully
jhegedus42
@jhegedus42
Aug 18 2016 17:54
hmmm, thanks @pfn , I look into that
@aafa how is your realm experience ? anything I need to watch out for ?
Alex Afanasev
@aafa
Aug 18 2016 17:58
@jhegedus42 hi! I have a small prove of concept, you can take a look here https://github.com/aafa/realm-sbt-plugin
jhegedus42
@jhegedus42
Aug 18 2016 17:59
thanks @aafa
Alex Reisberg
@a-reisberg
Aug 18 2016 18:00
Has anyone here used couchbase mobile?
It's nosql, and supports sync, which seems quite cool.
Alex Afanasev
@aafa
Aug 18 2016 18:01
i haven't made it to production use thou, it relies on modified annotation processor
jhegedus42
@jhegedus42
Aug 18 2016 18:01
i tried it @a-reisberg
Alex Reisberg
@a-reisberg
Aug 18 2016 18:02
Is it good/bad/...?
jhegedus42
@jhegedus42
Aug 18 2016 18:02
hmmm kinda too simple ....
Alex Reisberg
@a-reisberg
Aug 18 2016 18:02
What features does it miss?
jhegedus42
@jhegedus42
Aug 18 2016 18:03
don't remember exactly, it was too simple....
basicaly a KV store
queries were limited
Alex Reisberg
@a-reisberg
Aug 18 2016 18:04
I see. I was thinking of using it, but haven't tried. Realm definitely looks much more capable, except for the scala thing
jhegedus42
@jhegedus42
Aug 18 2016 18:05
does akka work on android ?
Niklas Klein
@Taig
Aug 18 2016 18:05
@pfn that view dsl looks very promising. Promising enough to get me actually off the xml
jhegedus42
@jhegedus42
Aug 18 2016 18:06
a friend made a bitemporal akka db on top of akka persistence
probably overkill
Alex Reisberg
@a-reisberg
Aug 18 2016 18:06
that definitely sounds overkill
jhegedus42
@jhegedus42
Aug 18 2016 18:07
:)
Alex Afanasev
@aafa
Aug 18 2016 18:07
@jhegedus42 actually it does. I've seen an activator template where fragments were connected with actors
to create kinda ping pong messaging
jhegedus42
@jhegedus42
Aug 18 2016 18:07
hmm
Perry
@pfn
Aug 18 2016 18:09
@Taig yeah, I'm pretty happy with how it's turning out
the IO stuff sucked, but this new case class approach is looking awesome
jhegedus42
@jhegedus42
Aug 18 2016 18:09
i try the hand written SQL approach first... that seems to be the way to go ... folks seem to use that here ...
Niklas Klein
@Taig
Aug 18 2016 18:10
Very straight-forward and easily extensible
... hate how gitter loves to embed half of a gist inline
Niklas Klein
@Taig
Aug 18 2016 18:14
But the viewtree case classes don't necessarily have to be defined as inner classes, do they?
Perry
@pfn
Aug 18 2016 18:15
no, they can be defined anywhere, you can put them in a package 'layouts' if you wanted
Niklas Klein
@Taig
Aug 18 2016 18:15
It's beautiful
But applying themes/styles will be a problem I suppose?
Perry
@pfn
Aug 18 2016 18:19
using style= doesn't work as with all DSL
jhegedus42
@jhegedus42
Aug 18 2016 18:19
Perry
@pfn
Aug 18 2016 18:19
applying themes yeah, there's no good way to pass the theme value into the constructor
@Taig using style= is out of the question for any layout DSL, but I might be able to come up with something for a theme injector
something like ViewTree.inflate(ctx, InflaterFunction, theme-to-inject-to-all)
theme-to-inject-to-all might be possible to be written as a discriminator function or partial function
so a theme can be set depending on input (3rd or 4th arg of view ctors, depending)
or perhaps the possibility of a ContextThemeWrapper
these things require more thought on how they would work best
Alex Afanasev
@aafa
Aug 18 2016 18:26
@jhegedus42 have you tried https://github.com/getquill/quill ?
jhegedus42
@jhegedus42
Aug 18 2016 18:33
@aafa not yet, it seems to need jdbc : https://github.com/getquill/quill#sql-contexts
after the disappointment with slick... i just might go with plain hand written sql, unless some says that there is a better way....
Perry
@pfn
Aug 18 2016 23:07
pfn/iota@f7b9471
I have emerged from the belly of the macro beast