Recently I had a problem that I needed to send some text from Android over webview to JavaScript, but with new lines included, problem was that webview didn't respect \r\n.

This is my solution:

...
receivedPacket = new DatagramPacket(buf, buf.length);
...
final String strReceivedPacket = new String(receivedPacket.getData(), 0, receivedPacket.getLength()).replaceAll("\r\n", "\\\\r\\\\n");

Just a few comments on my investigation about building and installing Android application.

In Linux go to root folder of your application and write something like:

./gradlew build

build means build.gradle actually, or something like  ./gradlew assembleDebug, with that you will build application with debug type. Check the source in /app/build.gradle.

After building we can install application with command like:

adb install -d -r myApp.apk

Where:

-d Direct an adb command to the only attached USB device.
-r Reinstall an exisiting app, keeping its data.

For example we have view:

<TextView
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="Hello World!"
	android:background="@drawable/black"/>

Notice line:

android:background="@drawable/black"

This means that I've created new file in drawable folder /app/src/main/res/drawable/black.xml which looks like:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <solid android:color="#ffffff" />
    <stroke android:width="1dip" android:color="#000000"/>
</shape>

In order to have responsive UI use AsyncTask.

Here is one example. 

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.stanko.myapplication.MainActivity"
    tools:showIn="@layout/activity_main">

    <EditText
        android:id="@+id/myCounter"
        android:layout_width="match_parent"
        android:layout_height="1200px"
        />

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/myCounter"
        android:text="Start"
        android:onClick="startCounter"/>

</RelativeLayout>

MainActivity.java:

public class fillEdit extends AsyncTask<Void, String, String> {

	@Override
	protected String doInBackground(Void... params) {
		for (Integer i=0; i<10000; i++) {
			try {
				Thread.currentThread().sleep(60);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			publishProgress(i.toString());
		}
		return null;
	}

	@Override
	protected void onProgressUpdate (String... result) {
		EditText myCounter = (EditText) findViewById(R.id.myCounter);
		myCounter.append(result[0]);
		myCounter.append("\n");
	}
}

public void startCounter (View view) {
	new fillEdit().execute();
}

Here note:

try {
  Thread.currentThread().sleep(60);
} catch (InterruptedException e) {
  e.printStackTrace();
}

I needed to slow down code execution to make UI responsive, I also needed try / catch block because otherwise I would receive error:

Error:(51, 49) error: unreported exception InterruptedException; must be caught or declared to be thrown

Also, note how I am adding new line:

myCounter.append("\n");