Code Monkey home page Code Monkey logo

androidtddbootstrap's Introduction

Android TDD bootstrap project

Master branch build status codecov.io Android Arsenal

An Android TDD bootstrap project, using a collection of new technology, obeying the best practices, inspired by some popular architectures, and developed with many handy tools.

Project structure

  • base is the so called architecture part, and base classes, best practice, etc.
  • Package organization
  • Package by layer v.s. package by feature, read more about the Package organization part of this blog, and Package by feature, not layer.
  • Both features and models are packaged by their functions. users and repos are model modules, each one provides a Repo API for upper level modules. splash and trending are feature modules, each one is a standalone module, implementing a single feature.
  • All modules can be composed together as a full APK, containing all features.
  • Module organization
  • Modules are organized by contributors in the contrib dir, that can separate code and responsibility as much as possible. Because each person has his own style and flavor, others should obey the style of contributor in each module, that's a very clear rule.
  • Feature modules are 100% decomposed, that makes each feature module as lightweight as possible, and activity is launched through string url.
  • business contains app specific business code, configurations, etc.
  • bridge module is just like a bridge, connecting modules together, like the image above.

Build tips

  • Sign key config
  • Place KeyStore file in some place, and create a TemplateKeyStore.properties, and config the KeyStore in it, include keystore, keystore.password, key.password, key.alias.
  • To clone all submodules, please use git clone --recursive [email protected]:Piasy/AndroidTDDBootStrap.git
  • use flavor to control server configuration, use build type to control log behavior
  • dev for development server, prod for production server
  • debug enable log and dev tools, disable crash and analytics, release against it

Why another bootstrap project?

From the beginning of the year 2015, our team started a new project, and before we developing functionality in detail, we have tried to create a well-architected project from scratch, with well designed network layer, data layer, asynchronous execution, communication between modules, and last but not least: unit test and integrated testing support. After several months of development, we found some drawbacks of our current architecture, and also found some popular architectures, then I decided to extract our original well designed architecture and make it open-source, with amendment according to the drawbacks and features from the new popular architectures we've found. Recently I have seen a lot of bootstrap/base Android projects, including JakeWharton's u2020, mobiwiseco's Android-Base-Project, etc, but none of these projects cover all the features I include in this AndroidTDDBootStrap project. That's why I want more people to see this repo, and I also want get feedback from more people to improve this project.

Architecture

Based on the project architecture I'm currently working on, YOLO, and inspired by popular architectures: Android Clean Architecture, Against Android Unit Tests: The Square way.

  • MVP: YaMvp, Yet another Mvp library. Super simple, but with enough functionality.
  • Dependency injection
  • Dagger2, A fast dependency injector for Android and Java.
  • ButterKnife, View "injection" library for Android.
  • Model layer, 完美的安卓 model 层架构(上)
  • OkHttp, An HTTP+SPDY client for Android and Java applications.
  • Retrofit, Type-safe HTTP client for Android and Java by Square, Inc.
  • Gson, A Java library that can be used to convert Java Objects into their JSON representation.
  • SQLBrite, A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations..
  • SQLDelight, Generates Java models from CREATE TABLE statements.
  • AutoValue, Generated immutable value classes for Java 1.6+.
  • auto-value-gson, AutoValue Extension to add Gson De/Serializer support.
  • auto-value-parcel, An Android Parcelable extension for Google's AutoValue.
  • Reactive programming
  • RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
  • RxAndroid, RxJava bindings for Android.
  • RxBinding, RxJava binding APIs for Android's UI widgets.
  • RxLifecycle, Lifecycle handling APIs for Android apps using RxJava.
  • Communication between modules: EventBus, Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
  • Image loader: Fresco, An Android library for managing images and the memory they use.
  • Other core libraries
  • SafelyAndroid, Build safely Android app, no more Activity not found error and Activity state loss error!
  • Router, Using string url to launch activities, allowing us decompose feature modules.
  • RetroLambda, Backport of Java 8's lambda expressions to Java 7, 6 and 5.
  • ThreeTenABP, An adaptation of the JSR-310 backport for Android.
  • AutoBundle, AutoBundle generates boilerplate code for field binding with android.os.Bundle.
  • FlexLayout, A powerful Android layout view that use java expression in layout params to describe relative positions.
  • Developer tools
  • XLog, Method call logging based on dexposed.
  • LeakCanary, A memory leak detection library for Android and Java.
  • ANR-WatchDog, A simple watchdog that detects Android ANR (Application Not Responding) error and throws a meaningful exception.
  • AndroidPerformanceMonitor, A transparent ui-block detection library for Android. (known as BlockCanary)
  • strictmode-notifier, Improving StrictMode's report on Android.
  • Timber, A logger with a small, extensible API which provides utility on top of Android's normal Log class.
  • OkHttp Logging Interceptor, An OkHttp interceptor which logs HTTP request and response data.
  • Ok2Curl, Convert OkHttp requests into curl logs.
  • Stetho, Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
  • android-git-sha-plugin, Automatically add current GIT SHA value to your apk. It can rise an error if the current git branch is dirty.
  • Codestyle, Customized base on Square java-code-styles.
  • Others
  • Iconfy, Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
  • Fabric, Crash report.
  • Once, A small Android library to manage one-off operations.
  • Unit test
  • Junit && Android Junit
  • Following the Square Way
  • Android Unmock Gradle Plugin, Gradle plugin to be used in combination with the new unit testing feature of the Gradle Plugin / Android Studio to use real classes for e.g. SparseArray.
  • mockito, Tasty mocking framework for unit tests in Java.
  • RESTMock, HTTP Server for Android Instrumentation tests.
  • Espresso
  • Continuous integration
  • Travis CI
  • Code quality, customized from Vincent Brison's vb-android-app-quality repo
  • AndroidCodeQualityConfig
  • Checkstyle, Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.
  • Find bugs, FindBugs is a defect detection tool for Java that uses static analysis to look for more than 200 bug patterns, such as null pointer dereferences, infinite recursive loops, bad uses of the Java libraries and deadlocks.
  • PMD, PMD is a source code analyzer.
  • Lint
  • Code coverage
  • Jacoco && Codecov

Dev tips

  • Create a new contrib module: ./new_contrib_module.sh contrib/<contributor name>/<module name>
  • Compose all modules together: ./install_app.sh <build type>
  • Buck build for each feature module: ./install_buck.sh contrib/piasy/trending or ./install_buck.sh app
  • You can also click the run button of AndroidStudio for each feature module, but it doesn't work for app module.
  • Create Activity
  • TODO use the MVP feature generator
  • Unit test
  • use the check*.sh script in buildsystem dir
  • Run ./buildsystem/ci.sh before git push.

Todo

  • CheckStyle
  • MVP source generator plugin
  • Espresso test
  • exopackage for each feature module
  • try MVVM
  • try React Native
  • try Kotlin

Coverage

codecov.io

Acknowledgement

  • Thanks for our team, YOLO.
  • Thanks for my colleague & mentor, promeG.

androidtddbootstrap's People

Contributors

piasy avatar zhoulujue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

androidtddbootstrap's Issues

请教:关于封装的问题

我这边的api发挥有一个简单的统一格式
{ "error": “”, //api是否出错 "results": “” //返回的data }
如果按照你的GithubUserSearchResult的写法,每个api都需要写一个对应的GithubUserSearchResult,但是如果使用发射封装一个HttpResponse,代码如下:
`public class HttpResponse {

@SerializedName("error")
private boolean error;

@SerializedName("results")
private T data;

}`
则不能使用auto-value-gson进行序列化和反序列化,请问像我这种api,应该怎么结合auto-value及相关的扩展封装一个HttpResponse

Compile issue

Hi

When i run
buck install appDevDebug

i get

BUILD FAILED: //model:src_release failed on step javac with an exception:
java.lang.NoSuchMethodError: com.squareup.javapoet.TypeName.isBoxedPrimitive()Z
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.squareup.javapoet.TypeName.isBoxedPrimitive()Z
at com.sun.tools.javac.main.Main.compile(Main.java:553)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at com.facebook.buck.jvm.java.Jsr199Javac.buildWithClasspath(Jsr199Javac.java:247)
at com.facebook.buck.jvm.java.Jsr199Javac.buildWithClasspath(Jsr199Javac.java:155)
at com.facebook.buck.jvm.java.JavacStep.tryBuildWithFirstOrderDeps(JavacStep.java:154)
at com.facebook.buck.jvm.java.JavacStep.execute(JavacStep.java:137)
at com.facebook.buck.step.DefaultStepRunner.runStepForBuildTarget(DefaultStepRunner.java:63)
at com.facebook.buck.rules.CachingBuildEngine.executeCommandsNowThatDepsAreBuilt(CachingBuildEngine.java:1223)
at com.facebook.buck.rules.CachingBuildEngine.access$300(CachingBuildEngine.java:113)
at com.facebook.buck.rules.CachingBuildEngine$3$1.call(CachingBuildEngine.java:304)
at com.facebook.buck.rules.CachingBuildEngine$3$1.call(CachingBuildEngine.java:294)
at com.facebook.buck.util.concurrent.WeightedListeningExecutorService$1.apply(WeightedListeningExecutorService.java:65)
at com.facebook.buck.util.concurrent.WeightedListeningExecutorService$1.apply(WeightedListeningExecutorService.java:61)
at com.google.common.util.concurrent.Futures$AsyncChainingFuture.doTransform(Futures.java:1442)
at com.google.common.util.concurrent.Futures$AsyncChainingFuture.doTransform(Futures.java:1433)
at com.google.common.util.concurrent.Futures$AbstractChainingFuture.run(Futures.java:1408)
at com.google.common.util.concurrent.Futures$2$1.run(Futures.java:1177)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: com.squareup.javapoet.TypeName.isBoxedPrimitive()Z
at com.ryanharter.auto.value.parcel.Parcelables.isValidType(Parcelables.java:47)
at com.ryanharter.auto.value.parcel.Parcelables.getParcelableType(Parcelables.java:63)
at com.ryanharter.auto.value.parcel.Parcelables.isValidType(Parcelables.java:51)
at com.ryanharter.auto.value.parcel.AutoValueParcelExtension.validateProperties(AutoValueParcelExtension.java:210)
at com.ryanharter.auto.value.parcel.AutoValueParcelExtension.generateClass(AutoValueParcelExtension.java:123)
at com.google.auto.value.processor.AutoValueProcessor.processType(AutoValueProcessor.java:424)
at com.google.auto.value.processor.AutoValueProcessor.process(AutoValueProcessor.java:143)
at com.facebook.buck.jvm.java.TracingProcessorWrapper.process(TracingProcessorWrapper.java:104)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
... 20 more

Found rharter/auto-value-parcel#64 , but it doesn't help

关于dagger2的Module

大神,你的module放在model中的是怎么做到的,我这里他并不能在model中生成Factory,是因为你用的buck的原因吗?

Could you provide some wikis

I am a beginner on this project, and it is true that some of third library I am not know before. The most important problem for me is that when I download this repo, open it with Android Studio (which vision is 2.3) , however it just building gradle project info. How could I continue ?
I just want to study this, but it seems that there is a steep hill for beginner.

clone 操作失败

$ git clone --recursive https://github.com/Piasy/AndroidTDDBootStrap.git
Cloning into 'AndroidTDDBootStrap'...
remote: Counting objects: 6201, done.
error: RPC failed; curl 56 SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

AutoValue error when compiling with Buck

→$./buckw build app:bin_devDebug
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/BriteDbConfig.java:12: error: package AutoValue_BriteDbConfig does not exist
        return new AutoValue_BriteDbConfig.Builder();
                                          ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/EventBusConfig.java:11: error: package AutoValue_EventBusConfig does not exist
        return new AutoValue_EventBusConfig.Builder();
                                           ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/GsonConfig.java:14: error: package AutoValue_GsonConfig does not exist
        return new AutoValue_GsonConfig.Builder();
                                       ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/HttpClientConfig.java:11: error: package AutoValue_HttpClientConfig does not exist
        return new AutoValue_HttpClientConfig.Builder();
                                             ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/RetrofitConfig.java:11: error: package AutoValue_RetrofitConfig does not exist
        return new AutoValue_RetrofitConfig.Builder();
                                           ^
Errors: 5. Warnings: 0.

BUILD FAILED: //base:src_release failed with exit code 1:
javac
stderr: /Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/BriteDbConfig.java:12: error: package AutoValue_BriteDbConfig does not exist
        return new AutoValue_BriteDbConfig.Builder();
                                          ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/EventBusConfig.java:11: error: package AutoValue_EventBusConfig does not exist
        return new AutoValue_EventBusConfig.Builder();
                                           ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/GsonConfig.java:14: error: package AutoValue_GsonConfig does not exist
        return new AutoValue_GsonConfig.Builder();
                                       ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/HttpClientConfig.java:11: error: package AutoValue_HttpClientConfig does not exist
        return new AutoValue_HttpClientConfig.Builder();
                                             ^
/Users/tommy/src/android/AndroidTDDBootStrap/base/src/main/java/com/github/piasy/bootstrap/base/model/provider/RetrofitConfig.java:11: error: package AutoValue_RetrofitConfig does not exist
        return new AutoValue_RetrofitConfig.Builder();
                                           ^
Errors: 5. Warnings: 0.

[-] PROCESSING BUCK FILES...FINISHED 0.1s
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 4.5s [100%] (435/445 JOBS, 0 UPDATED, 0 [0.0%] CACHE MISS)

Router is not work

I used ./install_app.sh to install a debug app on my mobile and failed to start trending activity.

Related log:

04-11 23:03:45.627 12155-12155/com.github.piasy.octostars E/Router: com.chenenyu.router.RouterBuildConfig
04-11 23:03:45.928 12155-12155/com.github.piasy.octostars E/Router: Could not find an Activity that matches the given uri.

First line is raised when Router.initialize(). RouterBuildConfig is not generated at compile-time, then Class.forname failed.

Second line is raised when Router.build(...).go(...) at splash view. Initialization is failed and it cannot find corresponding activity.

BTW, you forgot to add Router.openLog() at https://github.com/Piasy/AndroidTDDBootStrap/blob/master/contrib/business/src/main/java/com/github/piasy/octostars/BootstrapApp.java#L96 :)

FYI: update the router version to latest (0.7.0) could help.

有点疑惑

数据都来自网上,使用Gson来做解析变成了POJO,POJO继承serializable,能在bundle 中传递,那Auto-parcel在什么情况下使用?

Buck doesn't build: Execution failed for task ':buildDepCache'.

Getting this error when i try to build with buck:

[13:38:08 tommy@tumblr-MacBookPro-f0658b:~/src/android/AndroidTDDBootStrap] (master)
→$./buckw --stacktrace targets
 NO PREVIOUS SUCCESSFUL OKBUCK RUN
 RUNNING OKBUCK...

 DELETED OLD BUCK FILES
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
Parallel execution with configuration on demand is an incubating feature.
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
        at build_7cxr0118m5vyru20czgisz1ts.run(/Users/tommy/src/android/AndroidTDDBootStrap/app/build.gradle:29)
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instead.
extractDebugAnnotations is incompatible with java 8 sources and has been disabled.
extractReleaseAnnotations is incompatible with java 8 sources and has been disabled.
extractDebugAnnotations is incompatible with java 8 sources and has been disabled.
extractReleaseAnnotations is incompatible with java 8 sources and has been disabled.
extractDebugAnnotations is incompatible with java 8 sources and has been disabled.
extractReleaseAnnotations is incompatible with java 8 sources and has been disabled.
Jack is disabled, but one of the plugins you are using supports Java 8 language features.
Jack is disabled, but one of the plugins you are using supports Java 8 language features.
Jack is disabled, but one of the plugins you are using supports Java 8 language features.
Jack is disabled, but one of the plugins you are using supports Java 8 language features.
:buildDepCache
:model:generateDebugSqlDelightInterface UP-TO-DATE
:model:generateReleaseSqlDelightInterface UP-TO-DATE
:buildDepCache FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildDepCache'.
> /Users/tommy/src/android/AndroidTDDBootStrap/model/build/intermediates/unmocked-androidmodel.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 16.239 secs
== CSV Build Time Summary ==
Build time today: 0:43.394
Total build time: 0:43.394
(measured since 13 minutes ago)
== Build Time Summary ==
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 95% :buildDepCache (0:00.337)

== BUILD FAILED ==

 OKBUCK FAILED

compile error

Error:(170, 1) A problem occurred evaluating project ':app'.

Could not find property 'BUG_TAGS_API_SECRET' on com.bugtags.library.gradle.BugtagsExtension_Decorated@76e10c3f.

:)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.