<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Journal | Michael Zehender</title>
 <link href="http://tryge.com/atom.xml" rel="self"/>
 <link href="http://tryge.com/"/>
 <updated>2014-03-13T23:48:07-07:00</updated>
 <id>http://tryge.com/</id>
 <author>
   <name>Michael Zehender</name>
   <email>michael.zehender@tryge.com</email>
 </author>

 
 <entry>
   <title>The next programming language? Ceylon and Kotlin</title>
   <link href="http://tryge.com/2013/12/13/ceylon-and-kotlin/"/>
   <updated>2013-12-13T00:00:00-08:00</updated>
   <id>http://tryge.com/2013/12/13/ceylon-and-kotlin</id>
   <content type="html">&lt;p&gt;
	There are already a lot of resources that make &lt;b&gt;some&lt;/b&gt; comparison between ceylon, kotlin and Xs, where Xs stands for
	some JVM-based languages. I didn&#39;t include these in this post as I haven&#39;t spent enough time to analyze them in detail or
	they expose some major issues (regarding design, philosophy, readability, etc.) from my point of view.
&lt;/p&gt;&lt;p&gt;
	I probably have to stress that I don&#39;t say &lt;i&gt;Xs are flawed or bad&lt;/i&gt;, &lt;b&gt;they&#39;re just not right for me&lt;/b&gt; or I haven&#39;t spent
	enough time to evaluate them.
&lt;/p&gt;&lt;p&gt;
	Also I should note that this post is about my feeling to code in these languages and whether I could use them for products where a Java base already exists.
&lt;/p&gt;&lt;h2&gt;Why am I looking for a new language?&lt;/h2&gt;&lt;p&gt;
	If you ask someone why they are looking for a new language, they&#39;ll probably mention something like &lt;i&gt;boilerplate&lt;/i&gt;, &lt;i&gt;expressiveness&lt;/i&gt; or
	&lt;i&gt;productivity&lt;/i&gt;. I&#39;m not one of those guys:
	&lt;ul&gt;
		&lt;li&gt; boilerplate: yes,  in Java you write a lot of boilerplate code, but it is semi-automated by your IDE.&lt;/li&gt;
		&lt;li&gt; expressiveness: what does expressiveness exactly mean to you? I have always been able to express my design intentions in Java, so it can&#39;t be the expressive power - most likely you mean concise code and readability issues, however, I do think that Java code can be written in a readable way. And that you can write unreadable code in any non-trivial language.&lt;/li&gt;
		&lt;li&gt; productivity in a language: I sometimes read people claiming that they were almost instantly (a few days) more productive in a new language. How is this possible? To read up on the enormous API of todays languages takes weeks or months. In Java I don&#39;t think about how to do a specific task, I just do it. In a new language I have to learn how to do it, then I have to review whether there are better ways to express the idea or if there are hidden glitches. To cover the whole range of APIs and development tools that I have to use for my development tasks at work (from embedded development, to android app development, to desktop IDE-like tools, to web service and web application development) it takes at least 6 months until I &lt;b&gt;can&lt;/b&gt; get as productive as I am in Java right now - with (about) the same quality of my code. However I believe it is much longer than that.&lt;/li&gt;
	&lt;/ul&gt;
&lt;/p&gt;&lt;p&gt;
	So why am I looking for a new language?
&lt;/p&gt;&lt;p&gt;
	Firstly, I&#39;m continuously looking for new languages out of interest. I like to see new concepts and ideas - and often enough these ideas inspire me to improve something in the products I work on in Java. That is, because it is a concept and even though it might not have support for syntactic sugar it is expressible in Java and might be worth implementing.
&lt;/p&gt;&lt;p&gt;
	Secondly, there are issues with Java that I simply can&#39;t ignore: &lt;br /&gt;&lt;br /&gt;
	Often enough we run into problems because of incompatibilities of libraries as one transitive dependency is library X version 1 and another is library X version 2, of course they are incompatible. For some time we used an OSGi container to circumvent the problem, however there is overhead in managing the dependencies (e.g. not all Java libraries are osgified), so the solution was not ideal (for us). Instead, we restrict the libraries that we use, which works well, even though sometimes developers complain that &#39;it&#39; would be much easier with library &#39;X&#39;.&lt;br /&gt;&lt;br /&gt;
	Another issue is repository management, build systems and continuous integration. There are &lt;b&gt;no&lt;/b&gt; &lt;i&gt;standard tools&lt;/i&gt;. So if I need to replace an administrator I know I will have to plan at least 3 months of training. Worse, if something happens during this time it could cost us a lot of development time as our developers had to support the new team member. &lt;br /&gt;&lt;br /&gt;
	Deployment and the Update of our products are another hot topic, but I don&#39;t expect it to be better with a new language (it would really be a surprise), so I&#39;m not going into it. I wanted to note it down though.&lt;br /&gt;&lt;br /&gt;
	This starts trivial: there are some features of Java that have knowingly been implemented in a suboptimal way because of backwards compatibility issues - additional to the usual design flaws that creep into a large system. I won&#39;t list them here, &lt;a href=&#39;http://marksweep.blogspot.co.at/2011/10/java-8-backwards-compatibility.html&#39;&gt;they&lt;/a&gt; &lt;a href=&#39;http://c2.com/cgi/wiki?JavaDesignFlaws&#39;&gt;were&lt;/a&gt; &lt;a href=&#39;http://chrononsystems.com/blog/java-7-design-flaw-leads-to-huge-backward-step-for-the-jvm&#39;&gt;covered&lt;/a&gt; &lt;a href=&#39;http://www.javapuzzlers.com/&#39;&gt;enough&lt;/a&gt;. However the design flaws themselves are not the issue, &lt;b&gt;&lt;i&gt;the issue is the current strategy&lt;/i&gt;&lt;/b&gt; of how to deal with them - which is to do nothing. I&#39;ll probably work for another 50 years (yes, I am a workaholic...), if I keep true to my current view of things I&#39;ll always be coding (at least one third of my week), so even if Java is the new Cobol it won&#39;t be usable in 20 years.
&lt;/p&gt;&lt;p&gt;
	Lastly, even though I previously &lt;b&gt;was&lt;/b&gt; hard on the boilerplate/expressiveness/productivity argument, it &lt;b&gt;&lt;i&gt;is&lt;/i&gt;&lt;/b&gt; nice to have a clean, regular and immediately understandable language. These reasons are just not driving my cause.
&lt;/p&gt;&lt;h2&gt; First Impressions of Kotlin and Ceylon &lt;/h2&gt;&lt;p&gt;
	After spending a lot of time reading about the languages I implemented a simple project in both Ceylon and Kotlin. The most surprising thing for me was that even though the languages share a lot of ideas they have a completely different feel.
&lt;/p&gt;&lt;p&gt;
	Considering that Ceylon is about 18 months &#39;older&#39; than Kotlin (they were announced only 6 months apart, however, RedHat had been working on it for &#39;almost two years&#39; and Jetbrains for only &#39;almost a year&#39;) it is understandable that they are in a different stage of development. So don&#39;t take my comments regarding Kotlin too seriously. Also Jetbrains has made it clear, that they are in the process of designing the language and if something doesn&#39;t work they change it.
&lt;/p&gt;&lt;h3&gt;Kotlin&lt;/h3&gt;&lt;p&gt;
	One thing I noticed almost immediately is that Kotlin (at M6.2) is by far not finished. Some parts of the API are not consistent, e.g. for Java lists there are Extension Properties &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;head&lt;/code&gt; as well as Extension methods &lt;code&gt;first()&lt;/code&gt; and &lt;code&gt;firstOrNull()&lt;/code&gt;. My opinion is that there shouldn&#39;t be a multitude of methods how to perform the exact same &lt;i&gt;trivial&lt;/i&gt; task. But it also shows that there is no coherent design in place. I have the feeling that it is missing (or not published in any way) and that the current code does not express this design (if it exists).
&lt;/p&gt;&lt;p&gt;
	One more thing is that there is a real lack of introductory material on Kotlin. There is documentation, but it is in a very rough state and it doesn&#39;t make the vision of Kotlin clear. I don&#39;t know what I can expect from the language. For example, if there hadn&#39;t been a &lt;a href=&#39;http://medianetwork.oracle.com/video/player/2623518144001&#39;&gt;talk&lt;/a&gt; about reflection I&#39;d be completely in the dark whether reflection for Kotlin was supported or I&#39;d have to &#39;decode&#39; the JVM structures. Also I&#39;d like to know what to expect in M7 and M8 (so at least two milestones in advance).
&lt;/p&gt;&lt;p&gt;
	However, it does make a few topics very clear:
	&lt;ul&gt;
		&lt;li&gt;No compromises in Java compatibility. This is one of the things that drastically separates Kotlin from Ceylon. While it is possible in Ceylon to call Java-Code, the other way round it seems to be more difficult (when creating a ceylon project, the IDE has an &lt;i&gt;&lt;b&gt;option (sic!)&lt;/b&gt;&lt;/i&gt; to enable Java code calling Ceylon code and a warning that this might affect performance)&lt;/li&gt;
		&lt;li&gt;Compilation Speed matters, that is, Kotlin code should compile at least as fast as Java code (it doesn&#39;t at the moment).&lt;/li&gt;
		&lt;li&gt;Safe &amp;amp; Concise completes the mantra.&lt;/li&gt;
	&lt;/ul&gt;
	Especially the first point piqued my interest in Kotlin.
&lt;/p&gt;&lt;p&gt; One thing I have to remark is that Kotlin has a very familiar feeling, aside from syntax and API differences it still feels somewhat similar to Java coding - which is a good thing. I feel that all my experience with Java is helping me to write Kotlin code.&lt;/p&gt;&lt;h3&gt;Ceylon&lt;/h3&gt;&lt;p&gt;
	Ceylon&#39;s documentation is overwhelmingly complete and readable, I can only recommend reading the &lt;a href=&#39;http://ceylon-lang.org/documentation/1.0/tour/&#39;&gt;Tour of Ceylon&lt;/a&gt;. Also the language itself feels complete and consistent, however, it really feels like a new and completely different language. I&#39;d say that the barrier of using an existing Java library in Ceylon is higher than in Kotlin.
&lt;/p&gt;&lt;p&gt;
	What I find most impressive and intriguing about the language is the concept of union and intersection types. In a recent &lt;a href=&#39;http://ceylon-lang.org/blog/2013/12/13/three-legged-elephants/&#39;&gt;blog post&lt;/a&gt; Gavin King said that Ceylon had the most satisfying solution for combining &lt;i&gt;subtype polymorphism&lt;/i&gt; with &lt;i&gt;parametric polymorphism&lt;/i&gt;. I completely agree with this statement. I like the language not only for their solution of &lt;i&gt;generics&lt;/i&gt;, but also because it seems like a lot of consideration has been invested in every single feature of the language. This just makes the language very harmonic.
&lt;/p&gt;&lt;p&gt;
	Also infrastructure has been taken into account:
	&lt;ul&gt;
		&lt;li&gt;Modularity is built into the language&lt;/li&gt;
		&lt;li&gt;Dependencies are built into the language&lt;/li&gt;
		&lt;li&gt;There is a standard repository management system&lt;/li&gt;
		&lt;li&gt;It has a great meta-model of the language (event though I haven&#39;t found out how legacy Java modules are supported in the meta-model)&lt;/li&gt;
		&lt;li&gt;Simple, regular and powerful visibilities using a single annotation &lt;code&gt;shared&lt;/code&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/p&gt;&lt;p&gt;
	The concepts left a really good feeling about the language, however, there is one thing that is bugging me. My application took ages to compile! In the IDE it wasn&#39;t so apparent as I haven&#39;t used Eclipse for a long time and still remember Eclipse being really slow - but it might just be that it was the compiler that slowed things down. I really thought that I did something wrong when I built the whole application on the command line for the first time. I actually aborted with CTRL+C before I realized that it actually might take &lt;b&gt;this&lt;/b&gt; long to compile.
&lt;/p&gt;&lt;h2&gt;Direct Comparison&lt;/h2&gt;&lt;p&gt;
	I generally have to say that I like both languages a lot. Ceylon&#39;s design is much cleaner but Kotlin has a very familiar feel when coding (and regarding its design, it&#39;s not finished yet). Where Ceylon has brought OOP type systems to a whole new level, Kotlin concentrates on the most important pieces that improve upon Java like null-safety. Both languages allow me to &#39;overload&#39; a predefined set of operators and provide a way to define hierarchical structures easily. In the latter case I must say that I like Kotlin&#39;s solution of using anonymous extension methods more that the construction based approach taken by Ceylon. According to the &lt;a href=&#39;http://ceylon-lang.org/documentation/1.0/faq/language-design/#extension_methods&#39;&gt;Ceylon FAQ&lt;/a&gt; extension methods might make it into a subsequent release, so my hopes are still up that I get more flexibility for defining my hierarchical structures.
&lt;/p&gt;&lt;p&gt;
	It took me longer to get used to Ceylon&#39;s keywords and also its rhythm as they are really different compared to Java, but I was very satisfied with my result. In contrast, I caught Kotlin&#39;s syntax faster but the result didn&#39;t feel as satisfying. Probably that is because it felt &lt;i&gt;easier&lt;/i&gt; so I didn&#39;t have the same sense of accomplishment. In my Kotlin application I mostly used classes from the Java Platform as Kotlin&#39;s stdlib is not really complete yet whereas Ceylon provides their own language module where I needed to lookup &lt;b&gt;a lot of&lt;/b&gt; things - like how to append a list to another one and similar trivialities.
&lt;/p&gt;&lt;p&gt;
	What I really like about Kotlin is that I could start using it in any of my projects right now without a fuzz. There are a &lt;a href=&#39;http://confluence.jetbrains.com/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Gradle&#39;&gt;gradle plugin&lt;/a&gt;, a &lt;a href=&#39;http://confluence.jetbrains.com/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Maven&#39;&gt;maven plugin&lt;/a&gt; and &lt;a href=&#39;http://confluence.jetbrains.com/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Ant&#39;&gt;ant tasks&lt;/a&gt; for build integration and Kotlin even works on Android which is a big plus. It&#39;s different with Ceylon, I couldn&#39;t just add Ceylon code to my existing projects to add a new feature, from what I gather now (correct me if I&#39;m wrong), I&#39;d have to transform the modules to Ceylon modules where I could mix Ceylon with Java - IF I can do this with my build system. There is &lt;a href=&#39;https://groups.google.com/d/msg/ceylon-users/2vEeWgoNyZ0/LaNY7X75KlMJ&#39;&gt;proof&lt;/a&gt; that it is possible to run Ceylon on Android, however it doesn&#39;t give me the confidence to use it in my projects right now.
&lt;/p&gt;&lt;p&gt;
	What came as a surprise to me is that the Ceylon-IDE is a much nicer IDE than the Kotlin plugin for IntelliJ. I thought that Jetbrains who specializes in IDE&#39;s would invest more time in their plugin, but probably they are waiting until the final design decisions of the language have been made. As soon as Jetbrains starts to dogfood Kotlin I&#39;m sure the plugin will get better, however for the time being I prefer the Ceylon-IDE.
&lt;/p&gt;&lt;h2&gt; Conclusion &lt;/h2&gt;&lt;p&gt;
	I&#39;m a little dissatisfied with my findings, while I like both languages I am not able to use any of them now. On the one hand I have a really nice and elegant language that I can&#39;t use in my projects as it is not integrated in the toolchain and IDE; we use IntelliJ and we&#39;ll never change our Java IDE to Eclipse so we won&#39;t mix our code. On the other hand I have a language that I could use in my projects but which is unfinished and thus the risk of using it is too high (and also there are a lot of rough edges to it that need to be fixed before investing more time).
&lt;/p&gt;&lt;p&gt;
	If I&#39;d start a new project, I&#39;d at least investigate whether I could use Ceylon for it.
&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Building your Xtext DSL with Gradle</title>
   <link href="http://tryge.com/2013/08/24/building-xtext-dsl-from-gradle/"/>
   <updated>2013-08-24T00:00:00-07:00</updated>
   <id>http://tryge.com/2013/08/24/building-xtext-dsl-from-gradle</id>
   <content type="html">&lt;p&gt; 
	Xtext is almost what I expect from a tool that is designed to help with designing custom languages. I say almost, because it is heavily incorporated into eclipse IDE/Structures/etc. and therefore brings its own kind of problems. In this post I describe a sample gradle build that lets me compile my xtext languages outside of eclipse&#39;s grasp.
&lt;/p&gt;&lt;h2&gt; The example project &lt;/h2&gt;&lt;p&gt;
	I used the &#39;MyDsl&#39; stub that eclipse uses to initialize an xtext project i.e. our grammar looks like this:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;antlr&#39;&gt;&lt;span class=&#39;nl&#39;&gt;grammar&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;err&#39;&gt;org.xtext.example.mydsl.MyDsl&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;err&#39;&gt;with&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;err&#39;&gt;org.eclipse.xtext.common.Terminals&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;

&lt;span class=&#39;err&#39;&gt;generate&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;err&#39;&gt;myDsl&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;err&#39;&gt;&amp;quot;http&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;c&#39;&gt;//www.xtext.org/example/mydsl/MyDsl&amp;quot;&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;

&lt;span class=&#39;no&#39;&gt;Model&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;
&lt;span class=&#39;w&#39;&gt;	&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;greetings&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+=&lt;/span&gt;&lt;span class=&#39;no&#39;&gt;Greeting&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;;&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;
&lt;span class=&#39;w&#39;&gt;	&lt;/span&gt;
&lt;span class=&#39;nl&#39;&gt;Greeting&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;
&lt;span class=&#39;w&#39;&gt;	&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;no&#39;&gt;ID&lt;/span&gt;&lt;span class=&#39;w&#39;&gt; &lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;#39;!&amp;#39;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;;&lt;/span&gt;&lt;span class=&#39;w&#39; /&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
	Then I wrote my MWE generator script that uses a different structure than eclipse does.
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;
module org.xtext.example.mydsl.GenerateMyDsl

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*

var grammarURI = &quot;classpath:/org/xtext/example/mydsl/MyDsl.xtext&quot;
var projectName = &quot;mydsl&quot;
var runtimeProject = &quot;../${projectName}&quot;

Workflow {
    bean = StandaloneSetup {
    	scanClassPath = true
    	platformUri = &quot;${runtimeProject}/..&quot;
    }
    
    component = DirectoryCleaner {
    	directory = &quot;${runtimeProject}/src/main/gen&quot;
    }
    
    component = Generator {
    	pathRtProject = runtimeProject
    	projectNameRt = projectName
    	srcPath = &quot;/src/main/java&quot;
    	srcGenPath = &quot;/build/xtext-gen&quot;
    	
    	language = auto-inject {
    		uri = grammarURI
    
    		fragment = grammarAccess.GrammarAccessFragment auto-inject {
				xmlVersion = &quot;1.0&quot;
			}
    		fragment = ecore.EcoreGeneratorFragment auto-inject {
    		}
    		fragment = serializer.SerializerFragment auto-inject {
    			generateStub = false
    		}
    		fragment = resourceFactory.ResourceFactoryFragment auto-inject {
    		}
    		fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
    		}
    		fragment = validation.JavaValidatorFragment auto-inject {
    		}
    	}
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
	Anyone who has gone through the experience of customizing the generated mwe script should find his way with ease. However, for those of you who haven&#39;t had the pleaseure I&#39;ll briefly explain the differences that I introduced.
&lt;/p&gt;&lt;h3&gt;No generation of UI and test sources&lt;/h3&gt;&lt;p&gt;
	As I don&#39;t use eclipse I don&#39;t value the ui plugin and the test sources are not really helpful, they are more like a hint how you would do it on your own. Moreover it would complicate the setup extremely (at least for the tests) as xtext wants to generate the tests into its own project. You could configure the test project as your dsl project, however, then the test sources would be generated into the same directories as your application source.
&lt;/p&gt;&lt;h3&gt;Change structure where the source files are read and generated&lt;/h3&gt;&lt;p&gt;
	The generated source lives in the build folder, as gradle suggests it should. Your main source folder lives in &lt;code&gt;src/main/java&lt;/code&gt; of your project, but that you can change according to your preferences.
&lt;/p&gt;&lt;h3&gt;Generate an XMI file instead of the new default xtextbin&lt;/h3&gt;&lt;p&gt;
	I mainly included this change for you to see how it is done, so if you stumble upon a &lt;code&gt;&quot;missing resource /org/xtext/example/mydsl/MyDsl.xmi&quot;&lt;/code&gt; then eclipse has probably upgraded the xtext version in your IDE and generates a &lt;code&gt;MyDsl.xtextbin&lt;/code&gt; instead.
&lt;/p&gt;&lt;h3&gt;Use a java validator fragment instead of the default xtend generated one&lt;/h3&gt;&lt;p&gt;
	Using a java validator instead of an xtend one is just a move of convenience. I didn&#39;t want to compile xtend sources with gradle but still show that we can directly generate java helper classes like the validator (its practically the same for scoping).
&lt;/p&gt;&lt;h3&gt;The gradle build&lt;/h3&gt;&lt;p&gt;
	I&#39;ll leave out the dependencies part (with one exception), I wouldn&#39;t expect any reaction other than &lt;code&gt;&quot;those are a lot of dependencies&quot;&lt;/code&gt;. The exception is that we have to put our source folder (or the folder where you decide to put your *.xtext files) on the classpath. Xtext searches for the &lt;code&gt;xtext&lt;/code&gt; file referenced from the &lt;code&gt;mwe&lt;/code&gt; file on the classpath, therefore we have to provide it in this way.
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;apply&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;plugin:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;java&amp;#39;&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;repositories&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;flatDir&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;name:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;local&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;dirs:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;libs&amp;#39;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;configurations&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;xtext&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;extendsFrom&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;compile&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;sourceSets&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;main&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;dir&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;buildDir&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;xtext-res&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;),&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;builtBy:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;processLang&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;dependencies&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;c1&#39;&gt;// compile dependencies ...&lt;/span&gt;

	&lt;span class=&#39;n&#39;&gt;xtext&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;files&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;src/main/java&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
	&lt;span class=&#39;c1&#39;&gt;// other xtext dependencies&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;task&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;generateLang&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;type:&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;JavaExec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;inputs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;file&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;src/main/java/org/xtext/example/mydsl/GenerateMyDsl.mwe2&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;inputs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;file&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;src/main/java/org/xtext/example/mydsl/MyDsl.xtext&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;outputs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;dir&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;buildDir&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;xtext-gen&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

	&lt;span class=&#39;n&#39;&gt;standardOutput&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;OutputStream&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;public&lt;/span&gt; &lt;span class=&#39;kt&#39;&gt;void&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;write&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kt&#39;&gt;int&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{}&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;classpath&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;configurations&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;xtext&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;main&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher&amp;quot;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;args&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;src/main/java/org/xtext/example/mydsl/GenerateMyDsl.mwe2&amp;quot;&lt;/span&gt;
	
	&lt;span class=&#39;n&#39;&gt;doFirst&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;kt&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;.project&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;&amp;lt;?xml version=\&amp;quot;1.0\&amp;quot; encoding=\&amp;quot;UTF-8\&amp;quot;?&amp;gt;\n&amp;quot;&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;&amp;lt;projectDescription&amp;gt;&amp;quot;&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;&amp;lt;name&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;project&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;&amp;lt;/name&amp;gt;&amp;quot;&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;&amp;lt;/projectDescription&amp;gt;&amp;quot;&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;doLast&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;kt&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;.project&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;projectFile&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt;
		
		&lt;span class=&#39;kt&#39;&gt;def&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;pluginFile&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;plugin.xml&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;pluginFile&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;task&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;processLang&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;dependsOn:&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;generateLang&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;type:&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;Copy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;from&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;${buildDir}/xtext-gen&amp;quot;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;into&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;${buildDir}/xtext-res&amp;quot;&lt;/span&gt;

	&lt;span class=&#39;n&#39;&gt;exclude&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;**/*.java&amp;quot;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;exclude&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;**/*.g&amp;quot;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;compileJava&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;source&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;generateLang&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;outputs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;files&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;sourceSets&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;main&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;java&lt;/span&gt;
&lt;span class=&#39;n&#39;&gt;compileJava&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;dependsOn&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;processLang&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
	Basically we just define a new &lt;code&gt;JavaExec&lt;/code&gt; task, that is a task that executes a java program. We define our inputs to be our &lt;code&gt;xtext&lt;/code&gt; and &lt;code&gt;mwe&lt;/code&gt; files and our outputs to be in the &lt;code&gt;build/xtext-gen&lt;/code&gt; folder. We set the classpath to the dependencies that we defined in the xtext configuration and provide our &lt;code&gt;mwe&lt;/code&gt; file as an argument to the program.
&lt;/p&gt;&lt;p&gt;
	That would have been the whole story if it weren&#39;t for the fact that eclipse is *cough* well eclipse... so we do some extra work.
&lt;/p&gt;&lt;h3&gt;Generate eclipse project file&lt;/h3&gt;&lt;p&gt;
	When I first saw the message : &lt;code&gt;java.io.IOException: The path &#39;/mydsl/build/xtext-gen/org/xtext/example/mydsl/mydsl/Greeting.java&#39; is unmapped&lt;/code&gt; I was puzzled. Of course it wasn&#39;t there, your task is to generate it! After a few hours of frustrated searching and looking through the source code I stumbled upon the solution by accident. I was retracing my steps as it had already worked and it wasn&#39;t until I deleted the &lt;code&gt;.project&lt;/code&gt; file that I had to really breath very slowly and keep calm on purpose. After digging deeper it seems that xtext doesn&#39;t know the folder our project lies in because it uses emf resources that is a logical representation of the platform resources hiding their actual physical location. Actually I&#39;m not surprised at all, it just wouldn&#39;t have been enough that you have to configure the project name and location several times in the &lt;code&gt;mwe&lt;/code&gt; file, it just needed to forget the location of the project. The worst part is that it knows that it knows no location of *any* project but keeps quiet about it.
&lt;/p&gt;&lt;p&gt;
	After you know why the &lt;code&gt;.project&lt;/code&gt; file is important, you know why it&#39;s beeing generated and deleted afterwards again. We also delete the &lt;code&gt;plugin.xml&lt;/code&gt; file that is automatically generated (and honestly I didn&#39;t invest the time search for a way to deactivate the generation).
&lt;/p&gt;&lt;p&gt;
	The copy task makes sure that the java files don&#39;t and the tokens file does end up in the distributed jar file.
&lt;/p&gt;&lt;p&gt;
	Finally we add the generated java files be compiled by the &lt;code&gt;compileJava&lt;/code&gt; task and let the &lt;code&gt;compileJava&lt;/code&gt; task depend on our processLang task.
&lt;/p&gt;&lt;h2&gt; Conclusion &lt;/h2&gt;&lt;p&gt;
	If Xtext wasn&#39;t so involved with how eclipse projects are setup (and it isn&#39;t really difficult to make something like that configurable) and the dependencies would be more manageable (just look at the dependencies in the project) it would be the ideal tool for language development. Unfortunately this is not the case, but gradle gives us the possibility to circumvent most of the obstacles - but not all of them, e.g. I&#39;ve hidden an exception that the &lt;code&gt;META-INF/MANIFEST.MF&lt;/code&gt; file is not found in swallowing the complete standardOutput.
&lt;/p&gt;&lt;p&gt;
	The sources of the complete project can be &lt;a href=&#39;/downloads/mydsl.zip&#39;&gt;downloaded here&lt;/a&gt;.
&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Signing Your Custom AOSP Build With Your Release Keys</title>
   <link href="http://tryge.com/2013/07/12/signing-aosp-build/"/>
   <updated>2013-07-12T00:00:00-07:00</updated>
   <id>http://tryge.com/2013/07/12/signing-aosp-build</id>
   <content type="html">&lt;p&gt; The procedure described &lt;a href=&#39;http://www.kandroid.org/online-pdk/guide/release_keys.html&#39;&gt;here&lt;/a&gt; actually works. I only had to edit &lt;code&gt;sign_target_files_apks&lt;/code&gt; to change the display property (that was added in 4.2 or 4.1) so the version is correctly identified as a release version. &lt;/p&gt;&lt;p&gt; I am writing this because I searched the net for a solution - even after I found the web page above, as I didn&#39;t trust it - and didn&#39;t find sufficient proof to support the procedure. &lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Building android AOSP on Mac OS X Mountain Lion</title>
   <link href="http://tryge.com/2013/06/15/build-android-from-source-macosx/"/>
   <updated>2013-06-15T00:00:00-07:00</updated>
   <id>http://tryge.com/2013/06/15/build-android-from-source-macosx</id>
   <content type="html">&lt;p&gt;
I have been working with the Android AOSP source code for some time now and spent endless hours searching the internet for problems that arose on different occasions. Today I decided to note them down, on the one hand it is convenient for me to just look it up on my own blog, on the other hand you might find some of these notes useful. 
&lt;/p&gt;&lt;p&gt;
What I ran into today was upgrading from Android 4.0.3 to 4.2.2. I didn&#39;t expect any difficulties in compiling the new source as compiling Android 4.0.3 on my Mac OS X (Mountain Lion) worked like a charm for me. But of course I discovered something disturbing - when I ran &lt;code&gt;lunch 12&lt;/code&gt;, I got an error:
&lt;/p&gt;&lt;p&gt;

&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;xcrun: Error: failed to &lt;span class=&#39;nb&#39;&gt;exec &lt;/span&gt;real xcrun. &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;No such file or directory&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
build/core/combo/HOST_darwin-x86.mk:62: *****************************************************
build/core/combo/HOST_darwin-x86.mk:63: * Cannot find SDK 10.6 at /Developer/SDKs/MacOSX10.6.sdk
build/core/combo/HOST_darwin-x86.mk:65: * If you wish to build using higher version of SDK, 
build/core/combo/HOST_darwin-x86.mk:66: * try setting &lt;span class=&#39;nv&#39;&gt;BUILD_MAC_SDK_EXPERIMENTAL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;1 before 
build/core/combo/HOST_darwin-x86.mk:67: * rerunning this &lt;span class=&#39;nb&#39;&gt;command &lt;/span&gt;
build/core/combo/HOST_darwin-x86.mk:69: *****************************************************
build/core/combo/HOST_darwin-x86.mk:70: *** Stop..  Stop.

** Don&lt;span class=&#39;s1&#39;&gt;&amp;#39;t have a product spec for: &amp;#39;&lt;/span&gt;full_maguro&lt;span class=&#39;err&#39;&gt;&amp;#39;&lt;/span&gt;
** Do you have the right repo manifest?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;/p&gt;&lt;h2&gt; What the hell is it complaining about?&lt;/h2&gt;&lt;p&gt;
Quickly looking up what xcrun is doing I discovered it&#39;s some helper program do select the correct XCode version/sdk etc. It didn&#39;t suprise me that it failed as I don&#39;t have XCode installed. But why would it want somthing from XCode?
&lt;/p&gt;&lt;p&gt;
I don&#39;t really have an answer to that, but I discovered that some genius decided that everyone building on Mac OS X has XCode installed. There&#39;s no option nor flag nor anything else to disable the use of these XCode specific tools - at least I didn&#39;t find them. However, I don&#39;t want to complain about it (too much) so without further ado I&#39;ll tell you how to compile Android 4.2.2 on Mac OS X Mountain Lion. I&#39;ll even try to do it in a way that you can do it when starting from scratch. Please keep in mind that I had my system running for a long time so I might have missed some steps when trying to backtrack the essentials.
&lt;/p&gt;&lt;h2&gt; Setting up the build environment &lt;/h2&gt;&lt;p&gt;
At this point I should point out that there is an excellent documentation for setting up the environment &lt;a href=&#39;http://source.android.com/source/initializing.html&#39;&gt;here&lt;/a&gt; and if anything goes wrong you should check it and it might solve your problem.
&lt;/p&gt;&lt;h3&gt;Homebrew and Prequesites&lt;/h3&gt;&lt;p&gt;
I am using &lt;a href=&#39;http://mxcl.github.io/homebrew/&#39;&gt;brew&lt;/a&gt; to install packages that are not shipped with the os and will setup the build environment using it. Of course you are free to use whatever you prefer, but I can highly recommend brew. After your system is ready to brew (check it with &lt;code&gt;brew doctor&lt;/code&gt;), execute the following commands:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;brew install automake
brew tap homebrew/dupes
brew install apple-gcc42
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
Moreover you have to install Java 1.6, for that just open the Terminal and type &lt;code&gt;java -version&lt;/code&gt;. If you haven&#39;t installed it the system will prompt you whether you want to install it.
&lt;/p&gt;&lt;h3&gt;Prepare a virtual disk to hold the android source&lt;/h3&gt;&lt;p&gt;
The default file system on Mac OS X is case-insensitive, meaning that &lt;i&gt;&lt;b&gt;Test&lt;/b&gt;&lt;/i&gt; and &lt;i&gt;&lt;b&gt;test&lt;/b&gt;&lt;/i&gt; would refer to the same file or directory. For some reason there are files in the linux kernel that differ only in the case of a letter - this is something you&#39;d probably do after 72 hours of not sleeping and having a few drinks, at least that&#39;s the situation I imagine when trying to grasp why someone would do that... Anyhow, either you have a disk with a case-sensitive filesystem or you create a virtual disk and mount it. To create the virtual disk, mount it and enter the directory run:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;hdiutil create -type SPARSE -fs &lt;span class=&#39;s1&#39;&gt;&amp;#39;Case-sensitive Journaled HFS+&amp;#39;&lt;/span&gt; -size 40g ~/android.dmg
hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android
&lt;span class=&#39;nb&#39;&gt;cd&lt;/span&gt; /Volumes/android
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;Downloading the source&lt;/h3&gt;&lt;p&gt;
First we need to install &lt;code&gt;repo&lt;/code&gt; which is a program that helps to organize the git repositories.
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;mkdir ~/bin
&lt;span class=&#39;nv&#39;&gt;PATH&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;~/bin:&lt;span class=&#39;nv&#39;&gt;$PATH&lt;/span&gt;
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo &amp;gt; ~/bin/repo
chmod a+x ~/bin/repo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
If you have followed along, you&#39;re still in the root directory of the mounted disk. If not you&#39;ll have to &lt;code&gt;cd /Volumes/android&lt;/code&gt;. Finally to download the code run:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1.2 --config-name
repo sync
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
This will take a while, go do something else until it finishes.
&lt;/p&gt;&lt;h3&gt;Building for a device&lt;/h3&gt;&lt;p&gt;
These steps depend on the device you&#39;re building for, I will give you the steps for &lt;b&gt;Galaxy Nexus&lt;/b&gt; (maguro) and you have to adapt them accordingly. First download the necessary drivers from &lt;a href=&#39;https://developers.google.com/android/nexus/drivers&#39;&gt;the nexus driver page&lt;/a&gt; and extract them to &lt;code&gt;/Volumes/android&lt;/code&gt;. Now you should have a directory listing similar to this one:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;&lt;span class=&#39;nv&#39;&gt;$ &lt;/span&gt;&lt;span class=&#39;nb&#39;&gt;cd&lt;/span&gt; /Volumes/android
&lt;span class=&#39;nv&#39;&gt;$ &lt;/span&gt;ls
Makefile			external			libcore
abi				extract-broadcom-maguro.sh	libnativehelper
bionic				extract-imgtec-maguro.sh	ndk
bootable			extract-invensense-maguro.sh	out
build				extract-nxp-maguro.sh		packages
cts				extract-samsung-maguro.sh	pdk
dalvik				extract-widevine-maguro.sh	prebuilts
development			frameworks			sdk
device				gdk				system
docs				hardware			vendor
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
Now run each of the &lt;b&gt;extract-...&lt;/b&gt; shell scripts. You will be asked to accept its license and you should (well, otherwise the drivers won&#39;t be extracted). Also you might have to unlock your bootloader etc. but I&#39;ll leave that to you; it&#39;s a well documented procedure.
&lt;/p&gt;&lt;h3&gt; Building the source code &lt;/h3&gt;&lt;p&gt; Just to be on the safe side, the android build scripts depend on being executed by &lt;code&gt;bash&lt;/code&gt; therefore run it if you don&#39;t already. Moreover I had problems with &lt;code&gt;perlbrew&lt;/code&gt;, if you have it installed it&#39;d be wise to switch to the perl version that is shipped with Mac OS X now. &lt;/p&gt;&lt;p&gt;
Now there comes the time for the hack, download this &lt;a href=&#39;http://tryge.com/downloads/HOST_darwin-x86.mk&#39;&gt;file&lt;/a&gt; (&lt;b&gt; android-4.2.2_r1.2 only !!! &lt;/b&gt;) and overwrite the file in &lt;code&gt;build/core/combos/HOST_darwin-x86.mk&lt;/code&gt;. I changed the file to allow for manually overriding the host compilers &lt;code&gt;HOST_CC&lt;/code&gt; and &lt;code&gt;HOST_CXX&lt;/code&gt; and skip the xcode test if they are both present. I don&#39;t use makefiles at all so there might be a more elegant solution to the problem but this works. After you have replaced the files you can execute:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;bash&#39;&gt;. build/envsetup.sh
&lt;span class=&#39;nv&#39;&gt;HOST_CC&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;gcc-4.2 &lt;span class=&#39;nv&#39;&gt;HOST_CXX&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;g++-4.2 lunch 
make &lt;span class=&#39;nv&#39;&gt;HOST_CC&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;gcc-4.2 &lt;span class=&#39;nv&#39;&gt;HOST_CXX&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;g++-4.2 -j8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
This will again take a while and if you followed all the steps the compilation succeeds.
&lt;/p&gt;&lt;h2&gt; Final Notes &lt;/h2&gt;&lt;p&gt;
Most of the steps I presented here are from the &lt;a href=&#39;http://source.android.com/source/index.html&#39;&gt;official android documentation&lt;/a&gt; and I recommend reading these docs for further information or troubleshooting. I hope I could help some of you :)
&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using the new Android Build System and TDD</title>
   <link href="http://tryge.com/2013/02/28/android-gradle-build/"/>
   <updated>2013-02-28T00:00:00-08:00</updated>
   <id>http://tryge.com/2013/02/28/android-gradle-build</id>
   <content type="html">&lt;p&gt;
Today I ported our android build to use the new gradle based build system. As we heavily employ Test Driven Development I also wanted to be able to test drive our application without resorting to test on devices - that proved to be a challenge.
&lt;/p&gt;&lt;h2&gt;The new android build system&lt;/h2&gt;&lt;p&gt;
It is still in development and I guess far from being released, nevertheless it seems very promising to us as we build almost all of our Java-based software with gradle. The default setup is very simple, there are only 4 things to remember:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;the android plugin must be on the classpath for the build process&lt;/li&gt;
	&lt;li&gt;the project must apply the android plugin&lt;/li&gt;
	&lt;li&gt;you have to put the sources in the correct directories&lt;/li&gt;
	&lt;li&gt;you have to tell the android plugin where the android sdk is&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;
The following snippet shows an example &lt;code&gt;build.gradle&lt;/code&gt; like the one published in the &lt;a href=&#39;http://tools.android.com/tech-docs/new-build-system/user-guide&#39;&gt;official documentation&lt;/a&gt;:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;buildscript&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;repositories&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;mavenCentral&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

	&lt;span class=&#39;n&#39;&gt;dependencies&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;classpath&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;com.android.tools.build:gradle:0.3&amp;#39;&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;apply&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;plugin:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;android&amp;#39;&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;android&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;compileSdkVersion&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;15&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
You should also notice that the directory structure is different from a standard android project. Basically you have to put all the sources and resources into &lt;code&gt;src/main&lt;/code&gt;. Device tests have to go into &lt;code&gt;src/instrumentTest&lt;/code&gt;.
&lt;/p&gt;&lt;p&gt;
Finally create a new file &lt;code&gt;local.properties&lt;/code&gt; and put something like: &lt;code&gt;sdk.dir=/usr/local/android-sdk/r21.1&lt;/code&gt; into it. Please replace the path with your own.
&lt;/p&gt;&lt;h2&gt;Adding a task for unit tests&lt;/h2&gt;&lt;p&gt;
The android plugin doesn&#39;t have a task for standard unit tests which is quite unfortunate, therefore we have to add that. First we have to add a &lt;code&gt;sourceSet&lt;/code&gt; for our test. Reading the documentation we discover that the sourceSets are configured in the &lt;code&gt;android&lt;/code&gt; section. Naturally you would think you could just add an additional &lt;code&gt;sourceSet&lt;/code&gt;, but the following doesn&#39;t work.
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;android&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;sourceSets&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;test&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
			&lt;span class=&#39;n&#39;&gt;java&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;srcDir&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s1&#39;&gt;&amp;#39;src/test/java&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
			&lt;span class=&#39;n&#39;&gt;resources&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;srcDir&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s1&#39;&gt;&amp;#39;src/test/resources&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
		&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
First it seems to work, but when you try to use it:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;task&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;unitTest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nl&#39;&gt;type:&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;Test&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;dependsOn:&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;assemble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
        &lt;span class=&#39;n&#39;&gt;description&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;run unit tests&amp;quot;&lt;/span&gt;
        &lt;span class=&#39;n&#39;&gt;testClassesDir&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;project&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;android&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;sourceSetsContainer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;test&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;classesDir&lt;/span&gt;
        &lt;span class=&#39;n&#39;&gt;classpath&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;project&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;android&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;sourceSetsContainer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;test&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;runtimeClasspath&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
It just tells you:
&lt;/p&gt;
&lt;p&gt;&lt;code style=&#39;color: red;&#39;&gt;Could not find property &amp;#39;output&amp;#39; on source set test.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;
In other words, we can find the source set, but we cannot access the directory where the classes are - and therefore cannot run the tests.
&lt;/p&gt;&lt;h3&gt;Hacky workaround&lt;/h3&gt;&lt;p&gt;
I wasn&#39;t in the mood to give up, probably there is another way to access the correct directories but here is what I came up with:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;apply&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;plugin:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;android&amp;#39;&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;android&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;compileSdkVersion&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;15&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;sourceSets&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;java&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;srcDir&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s1&#39;&gt;&amp;#39;src/test/java&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
		&lt;span class=&#39;n&#39;&gt;resources&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;srcDir&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s1&#39;&gt;&amp;#39;src/test/resources&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;configurations&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;extendsFrom&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;runtime&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestRuntime&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;extendsFrom&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;dependencies&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;files&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;$project.buildDir/classes/release&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;task&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;unitTest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nl&#39;&gt;type:&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;Test&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;dependsOn:&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;assemble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;description&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s2&#39;&gt;&amp;quot;run unit tests&amp;quot;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;testClassesDir&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;project&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;sourceSets&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;unitTest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;classesDir&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;classpath&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;project&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;sourceSets&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;unitTest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;runtimeClasspath&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;check&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;dependsOn&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;unitTest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
We define a standard java sourceSet, this works as the android plugin uses the &lt;code&gt;JavaBasePlugin&lt;/code&gt;. In the dependencies section we declare our dependency to the application code - as you might see, this is the hacky part and I will search for a better solution in the next few days. If there is one I will post an update. Last we define our &lt;code&gt;Test&lt;/code&gt; task and declare it to be executed in the check phase.
&lt;/p&gt;&lt;h2&gt;Robolectric Tests&lt;/h2&gt;&lt;p&gt;
This gives us unit tests, but it doesn&#39;t give us the capabilities to test source code that depends on the android API. Of course that doesn&#39;t make a lot of sense therefore we will integrate &lt;a href=&#39;http://pivotal.github.com/robolectric/&#39;&gt;Robolectric&lt;/a&gt; to drive our tests.
&lt;/p&gt;&lt;p&gt;
First we add additional dependencies to our dependencies section so it looks like this:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;groovy&#39;&gt;&lt;span class=&#39;n&#39;&gt;repositories&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;mavenCentral&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;

&lt;span class=&#39;n&#39;&gt;dependencies&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;files&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s2&#39;&gt;&amp;quot;$project.buildDir/classes/release&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;junit:junit:4.10&amp;#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;org.mockito:mockito-core:1.9.0&amp;#39;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;com.google.android:android:4.0.1.2&amp;#39;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;unitTestCompile&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;com.pivotallabs:robolectric:1.2&amp;#39;&lt;/span&gt;
	&lt;span class=&#39;n&#39;&gt;configurations&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;unitTestCompile&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;exclude&lt;/span&gt; &lt;span class=&#39;nl&#39;&gt;group:&lt;/span&gt; &lt;span class=&#39;s1&#39;&gt;&amp;#39;com.google.android.maps&amp;#39;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
We just add a dependency on the android API and robolectric and exclude the maps API which isn&#39;t necessary if you don&#39;t use it. Otherwise you just have to download it yourself as google doesn&#39;t permit its upload to maven central. &lt;i&gt;Don&#39;t forget to declare a repository where gradle can find the dependencies.&lt;/i&gt;
&lt;/p&gt;&lt;h3&gt;Writing the Test&lt;/h3&gt;&lt;p&gt;
As our project structure is now different from the standard android project structure, we have to tell Robolectric where our &lt;code&gt;AndroidManifest.xml&lt;/code&gt; and the other resources are. To do that we define our own runner:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;java&#39;&gt;&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;com.xtremelabs.robolectric.RobolectricTestRunner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;;&lt;/span&gt;
&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;org.junit.runners.model.InitializationError&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;;&lt;/span&gt;
&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;java.io.File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;;&lt;/span&gt;

&lt;span class=&#39;kd&#39;&gt;public&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;nc&#39;&gt;HelloWorldRunner&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;extends&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;RobolectricTestRunner&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;kd&#39;&gt;public&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;HelloWorldRunner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;Class&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;testClass&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;throws&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;InitializationError&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;kd&#39;&gt;super&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;testClass&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;n&#39;&gt;File&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;src/main&amp;quot;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;));&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
With this runner we can write a simple test case:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;java&#39;&gt;&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;org.junit.Test&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;;&lt;/span&gt;
&lt;span class=&#39;kn&#39;&gt;import&lt;/span&gt; &lt;span class=&#39;nn&#39;&gt;org.junit.runner.RunWith&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;;&lt;/span&gt;

&lt;span class=&#39;nd&#39;&gt;@RunWith&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;n&#39;&gt;HelloWorldRunner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;.&lt;/span&gt;&lt;span class=&#39;na&#39;&gt;class&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kd&#39;&gt;public&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;nc&#39;&gt;HelloWorldTest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;nd&#39;&gt;@Test&lt;/span&gt;
	&lt;span class=&#39;kd&#39;&gt;public&lt;/span&gt; &lt;span class=&#39;kt&#39;&gt;void&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;testInstantiation&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;()&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;{&lt;/span&gt;
		&lt;span class=&#39;k&#39;&gt;new&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;HelloWorldActivity&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;();&lt;/span&gt;
	&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
I know it doesn&#39;t look like much, but try to run this testcase without Robolectric and you will see that it is really necessary.
&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;
Gradle is a great build system and we could easily extend the android plugin with ordinary unit tests. I think it is the right choice for the new android build tool and I am looking forward to using it.
&lt;/p&gt;&lt;p&gt;
&lt;a href=&#39;/downloads/hello-world-nab.zip&#39;&gt;Download&lt;/a&gt; the whole example project.
&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Go Controversial 1 - What about proper Constructors?</title>
   <link href="http://tryge.com/2013/02/27/go-constructors/"/>
   <updated>2013-02-27T00:00:00-08:00</updated>
   <id>http://tryge.com/2013/02/27/go-constructors</id>
   <content type="html">&lt;p&gt;
When I first started programming in go, I found it irritating that there is no custom initialization phase when an &quot;object&quot; is being constructed. As I have heard some complaints about that and I&#39;ve already made up my mind, I will share my thoughts here. In this article I use the term constructor to refer to the concept as it is used in C++ or Java - not go&#39;s concept of constructors (which are factory functions).
&lt;/p&gt;&lt;h2&gt;Initialization&lt;/h2&gt;&lt;p&gt;
Each type has a zero value, e.g. the zero value for &lt;code&gt;int&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;. Optimally a type is ready to use with its zero value, but sometimes this isn&#39;t enough and we will use composite literals. A composite literal creates a new instance of the specified type and allows one to provide initialization for the fields. Suppose we have the following piece of code:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;go&#39;&gt;&lt;span class=&#39;kd&#39;&gt;type&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;SomeStruct&lt;/span&gt; &lt;span class=&#39;kd&#39;&gt;struct&lt;/span&gt; &lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;
	&lt;span class=&#39;nx&#39;&gt;A&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;B&lt;/span&gt; &lt;span class=&#39;kt&#39;&gt;string&lt;/span&gt;
	&lt;span class=&#39;nx&#39;&gt;C&lt;/span&gt; &lt;span class=&#39;kt&#39;&gt;int&lt;/span&gt;
	&lt;span class=&#39;nx&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;kt&#39;&gt;int&lt;/span&gt;
&lt;span class=&#39;p&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
SomeStruct is a complex type and has 3 exported fields and a private one. To initialize an instance we would write something like this:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;go&#39;&gt;&lt;span class=&#39;nx&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;:=&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;SomeStruct&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;first&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;second&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
In this way you can initialize all the exported fields of a struct. Now there&#39;s a question, how would you fit in a magic function that is automatically called upon instance creation. It obviously wouldn&#39;t make much sense to call it before the fields had been initialized, therefore it must be after that.
&lt;/p&gt;&lt;h3&gt;What would such an initialization function do?&lt;/h3&gt;&lt;p&gt;
It would probably allocate data for private fields and do something with the already initialized fields.
&lt;/p&gt;&lt;h3&gt;What if there is an error?&lt;/h3&gt;&lt;p&gt;
The only way to react is to &lt;code&gt;panic&lt;/code&gt; as you don&#39;t have a return value to pass an error. But that is against the philosophy of go, look at the statement again:
&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;go&#39;&gt;&lt;span class=&#39;nx&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;:=&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;SomeStruct&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;{&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&amp;quot;first&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&amp;quot;second&amp;quot;&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;,&lt;/span&gt; &lt;span class=&#39;mi&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;p&#39;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
It does look harmless, doesn&#39;t it? We just declared a new variable that is initialized with this composite literal.
&lt;/p&gt;&lt;h3&gt;How can we reason about it?&lt;/h3&gt;&lt;p&gt;Very simple, nothing bad can happen (&lt;i&gt;except&lt;/i&gt; if you run out of memory). However, if a magic function was called instead, you could not reason about this statement without looking into the code that implements the type. It could do anything, like opening a connection to the SETI project and wait for them to announce that they have found aliens.
&lt;/p&gt;&lt;p&gt; But there&#39;s a more pressing problem, what about the following piece of code:&lt;/p&gt;&lt;div class=&#39;highlight&#39;&gt;&lt;pre&gt;&lt;code class=&#39;go&#39;&gt;&lt;span class=&#39;kd&#39;&gt;var&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;nx&#39;&gt;SomeStruct&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;
When do you suggest this magic function should be called?
&lt;/p&gt;&lt;h3&gt;But I really do need a constructor!&lt;/h3&gt;&lt;p&gt;
Actually I&#39;ve never been fond of constructors, they don&#39;t really communicate the intent I would like to see. When writing Java code I prefer static factory methods and similarly that&#39;s the way to go - just write a factory function. That&#39;s how the concept of go constructors are defined. A function that returns an instance of a type is a constructor for that type. It also solves the problem of reasoning, everyone knows that a function call can cause/detect errors in one way or the other.
&lt;/p&gt;&lt;p&gt;I&#39;ve heard the argument that it is still possible to work with not initialized structures. Firstly, I think that is always possible and secondly, you shouldn&#39;t worry about that. You can (should) provide documentation so that everybody knows how to use your API and if you really want to prohibit the use of an uninitialized type, return an interface instead and don&#39;t export your actual type.
&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;
The concept of Java/C++ constructors doesn&#39;t fit into the philosophy of go, there&#39;s a conflict with reasoning about variable declarations and composite literals. If you need initialization, provide a factory method. If you want to prevent the possibility of using your instances uninitialized return an interface and don&#39;t export your actual type.
&lt;/p&gt;</content>
 </entry>
 
 
</feed>
