Is anybody able to run AndroidStudio ?

Hi guys,

I would really like to be able to run AndroidStudio in FreeBSD.
I have got abd working already.

I tried to download Android Studio for Linux and then run
bash -x studio.sh

It hangs without giving any arrors at this line (newlines added it for readability)
Code:
/usr/local/openjdk8/bin/java -classpath /home/p/download/tmp-android/android-studio/lib/bootstrap.jar:
/home/p/download/tmp-android/android-studio/lib/extensions.jar:
/home/p/download/tmp-android/android-studio/lib/util.jar:
/home/p/download/tmp-android/android-studio/lib/jdom.jar:
/home/p/download/tmp-android/android-studio/lib/log4j.jar:
/home/p/download/tmp-android/android-studio/lib/trove4j.jar:
/home/p/download/tmp-android/android-studio/lib/jna.jar:
/usr/local/openjdk8/lib/tools.jar -Xms256m -Xmx1280m -XX:
ReservedCodeCacheSize=240m -XX:
+UseConcMarkSweepGC -XX:
SoftRefLRUPolicyMSPerMB=50
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djna.nosys=true
-Djna.boot.library.path= -da -Dawt.useSystemAAFontSettings=lcd
-Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine
-XX:ErrorFile=/home/p/java_error_in_STUDIO_%p.log
-XX:HeapDumpPath=/home/p/java_error_in_STUDIO.hprof
-Didea.paths.selector=AndroidStudio3.2
-Djb.vmOptionsFile=/home/p/download/tmp-android/android-studio/bin/studio64.vmoptions -Didea.platform.prefix=AndroidStudio -Didea.jre.check=true com.intellij.idea.Main

let me know, any help is appreciated.
bye
Nicola
 
I have tried the procedure. it takes some hours.

in short, it works, in the sense that after applying it Android Studio starts up.

There are two problems in the the procedure:

1] (minor) it is supposed you installed the linux compatibility layer, see chapter 10 of the
FreeBSD handbook for that.

2] The patch file for the Java code is not available for download, you will need to do the modifications by hand.
It is not a big deal, just 4 lines to add in total. They are trivial code lines.

Other problems:
After starting Android Studio complains that:
1] OpenJDK shows intermittent performance and UI issues. We recommend using the Oracle JRE/JDK.
2] External file changes sync may be slow: Native file watcher is not supported on this platform

My Samsung Glaxy Note 8 broke on day 31 Dec, I am using an old dino-phone which
is not recognized in AndroidStudio, I am reluctant in making further experiments untill i will have a new
phone.

Up to now, i was NOT ABLE to compile and run on phone a simple "hello world" program, that
will require further experiments. I am running FreeBSD in a VM so i must take care of some extra
details. Maybe, running FBS on metal, after the patch it all works, i can't say by now.

Hope it helps quanquan
bye
n.
 
I just found brandelf gives me wired results, that is maybe the reason why I can't
get Android Studio to compile stuff. I opened another thread, here.
 
I saw that you are happy with API compat layers.
Would Wine be an option?
A little bit heavier than Linuxulator but still lighter than full blown virtualization.

Also, do you need Android Studio (the fat IDE) or are you just wanting to do software development and get the debug / build cycle going? If so, then I use a mixture of lang/gnatdroid-armv7 and the CLI command line tools.
 
If i can get the grip on the API compat i could use it for other things as well.
Unfortunately by now it eludes my understanding.

It is from the time of Linux Mandrake i don't try Wine, i remember at that remote epoch it was not working very well ... but 20 years have passed, it can be an option, i will consider it.

Unfortunately I learnt Android programming when Android Studio was already the main tool in business and Google docs were all talking about Android Studio procedures. I can try to switch to command line development, but it will take some time.
 
I can run studio with the script below changed a bit from the original studio.sh, I had to install sdk etc. manually in the beginning. Now I can even run studio self-updates. Even ndk is working.
You have to download the android build-tools manually, too.
In the "Project Structure" Settings disable "use embedded JDK" and set it to
/usr/local/openjdk8 (in my case).
Download and unpack the android ndk for linux by hand somewhere and set the path accordingly (if you need native code)

I have a single problem: I have to disable aapt2 and use aapt instead (by setting
android.enableAapt2=false in the project's gradle.properties file), which is not any more possible with gradle later than 4.1. Maybe someone has an idea about this?

I can't upload my script because it has a non-allowed extension :mad: Copied below.


Bash:
#!/bin/sh
#
# ---------------------------------------------------------------------
# Android Studio startup script.
# ---------------------------------------------------------------------
#

# https://stackoverflow.com/a/44202755
export LC_NUMERIC="en_US.UTF-8"
JAVA_HOME=/usr/local/openjdk8
JDK=$JAVA_HOME
JAVA_LOCATION=$JDK
TMPDIR=/usr/tmp
TEMP=$TMPDIR

message()
{
  TITLE="Cannot start Android Studio"
  if [ -n "`which zenity`" ]; then
    zenity --error --title="$TITLE" --text="$1"
  elif [ -n "`which kdialog`" ]; then
    kdialog --error "$1" --title "$TITLE"
  elif [ -n "`which xmessage`" ]; then
    xmessage -center "ERROR: $TITLE: $1"
  elif [ -n "`which notify-send`" ]; then
    notify-send "ERROR: $TITLE: $1"
  else
    echo "ERROR: $TITLE\n$1"
  fi
}

isJDK()
{
  if [ -z $1 ] || [ ! -x "$1/bin/java" ]; then
    return 1
  else
    return 0
  fi
}

UNAME=`which uname`
GREP=`which egrep`
GREP_OPTIONS=""
CUT=`which cut`
READLINK=/compat/linux/usr/bin/readlink
#READLINK=`which readlink`
XARGS=`which xargs`
DIRNAME=`which dirname`
MKTEMP=`which mktemp`
RM=`which rm`
CAT=`which cat`
TR=`which tr`

if [ -z "$UNAME" -o -z "$GREP" -o -z "$CUT" -o -z "$MKTEMP" -o -z "$RM" -o -z "$CAT" -o -z "$TR" ]; then
  message "Required tools are missing - check beginning of \"$0\" file for details."
  exit 1
fi

OS_TYPE=`"$UNAME" -s`

# ---------------------------------------------------------------------
# Ensure IDE_HOME points to the directory where the IDE is installed.
# ---------------------------------------------------------------------
SCRIPT_LOCATION=$0
if [ -x "$READLINK" ]; then
  while [ -L "$SCRIPT_LOCATION" ]; do
    SCRIPT_LOCATION=`"$READLINK" -e "$SCRIPT_LOCATION"`
  done
fi

IDE_HOME=/data/compile/android/android-studio/
IDE_BIN_HOME=/data/compile/android/android-studio/bin/

#IDE_BIN_HOME=`dirname "$SCRIPT_LOCATION"`
if [ "$IDE_BIN_HOME" = "." ]; then
  IDE_HOME=".."
else
  IDE_HOME=`dirname "$IDE_BIN_HOME"`
fi

# ---------------------------------------------------------------------
# Locate a JDK installation directory which will be used to run the IDE.
# Try (in order): STUDIO_JDK, studio.jdk, ../jre, JDK_HOME, JAVA_HOME, "java" in PATH.
# ---------------------------------------------------------------------
#JDK=""
if isJDK $STUDIO_JDK; then
  JDK="$STUDIO_JDK"
fi

if [ "$JDK" = "" ] && [ -s "$HOME/.AndroidStudio3.2/config/studio.jdk" ]; then
  JDK=`"$CAT" $HOME/.AndroidStudio3.2/config/studio.jdk`
  if [ ! -d "$JDK" ]; then
    JDK="$IDE_HOME/$JDK"
  fi
  if ! isJDK $JDK; then
    JDK=""
  fi
fi

if [ "$JDK" = "" ] && [ "$OS_TYPE" = "Linux" ] &&
   [ -x "$IDE_HOME/jre/bin/java" ] && "$IDE_HOME/jre/bin/java" -version > /dev/null 2>&1 ; then
  JDK="$IDE_HOME/jre"
fi

if [ "$JDK" = "" ] && isJDK $JDK_HOME; then
  JDK="$JDK_HOME"
fi

if [ "$JDK" = "" ]; then
  if isJDK $JAVA_HOME; then
    JDK="$JAVA_HOME"
  else
    JAVA_BIN_PATH=`which java`
    if [ -n "$JAVA_BIN_PATH" ]; then
      if [ "$OS_TYPE" = "FreeBSD" -o "$OS_TYPE" = "MidnightBSD" ]; then
        JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-`
        if [ -x "$JAVA_LOCATION/bin/java" ]; then
          JDK="$JAVA_LOCATION"
        fi
      elif [ "$OS_TYPE" = "SunOS" ]; then
        JAVA_LOCATION="/usr/jdk/latest"
        if [ -x "$JAVA_LOCATION/bin/java" ]; then
          JDK="$JAVA_LOCATION"
        fi
      elif [ "$OS_TYPE" = "Darwin" ]; then
        JAVA_LOCATION=`/usr/libexec/java_home`
        if [ -x "$JAVA_LOCATION/bin/java" ]; then
          JDK="$JAVA_LOCATION"
        fi
      fi
    fi

    if [ -z "$JDK" -a -x "$READLINK" -a -x "$XARGS" -a -x "$DIRNAME" ]; then
      JAVA_LOCATION=`"$READLINK" -f "$JAVA_BIN_PATH"`
      case "$JAVA_LOCATION" in
        */jre/bin/java)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          if [ ! -d "$JAVA_LOCATION/bin" ]; then
            JAVA_LOCATION="$JAVA_LOCATION/jre"
          fi
          ;;
        *)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          ;;
      esac
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    fi
  fi
fi

JAVA_BIN="$JDK/bin/java"
if [ ! -x "$JAVA_BIN" ]; then
  JAVA_BIN="$JDK/jre/bin/java"
fi

echo $JAVA_BIN

if [ -z "$JDK" ] || [ ! -x "$JAVA_BIN" ]; then
  message "No JDK found. Please validate either STUDIO_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation."
  exit 1
fi

VERSION_LOG=`"$MKTEMP" -t java.version.log.XXXXXX`
JAVA_TOOL_OPTIONS= "$JAVA_BIN" -version 2> "$VERSION_LOG"
"$GREP" "64-Bit|x86_64|amd64" "$VERSION_LOG" > /dev/null
BITS=$?
"$RM" -f "$VERSION_LOG"
test ${BITS} -eq 0 && BITS="64" || BITS=""

# ---------------------------------------------------------------------
# Collect JVM options and IDE properties.
# ---------------------------------------------------------------------
if [ -n "$STUDIO_PROPERTIES" ]; then
  IDE_PROPERTIES_PROPERTY="-Didea.properties.file=$STUDIO_PROPERTIES"
fi

VM_OPTIONS=""
VM_OPTIONS_FILES_USED=""
for vm_opts_file in "$IDE_BIN_HOME/studio$BITS.vmoptions" "$OS_SPECIFIC_BIN_DIR/studio$BITS.vmoptions" "$HOME/.AndroidStudio3.2/studio$BITS.vmoptions" "$STUDIO_VM_OPTIONS"; do
  if [ -r "$vm_opts_file" ]; then
    VM_OPTIONS_DATA=`"$CAT" "$vm_opts_file" | "$GREP" -v "^#.*" | "$TR" '\n' ' '`
    VM_OPTIONS="$VM_OPTIONS $VM_OPTIONS_DATA"
    if [ -n "$VM_OPTIONS_FILES_USED" ]; then
      VM_OPTIONS_FILES_USED="$VM_OPTIONS_FILES_USED,"
    fi
    VM_OPTIONS_FILES_USED="$VM_OPTIONS_FILES_USED$vm_opts_file"
  fi
done

IS_EAP="false"
if [ "$IS_EAP" = "true" ]; then
  OS_NAME=`echo "$OS_TYPE" | "$TR" '[:upper:]' '[:lower:]'`
  AGENT_LIB="yjpagent-$OS_NAME$BITS"
  if [ -r "$IDE_BIN_HOME/lib$AGENT_LIB.so" ]; then
    AGENT="-agentlib:$AGENT_LIB=disablealloc,delay=10000,probe_disable=*,sessionname=AndroidStudio3.2"
  fi
fi

CLASSPATH="$IDE_HOME/lib/bootstrap.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/extensions.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/util.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/jdom.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/log4j.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/trove4j.jar"
CLASSPATH="$CLASSPATH:$IDE_HOME/lib/jna.jar"
CLASSPATH="$CLASSPATH:$JDK/lib/tools.jar"
if [ -n "$STUDIO_CLASSPATH" ]; then
  CLASSPATH="$CLASSPATH:$STUDIO_CLASSPATH"
fi

if [ -n "$JAVA_TOOL_OPTIONS" -a "$JAVA_TOOL_OPTIONS" != "${JAVA_TOOL_OPTIONS%-javaagent*jayatanaag.jar*}" ] ; then
  export _ORIGINAL_JAVA_TOOL_OPTIONS="$JAVA_TOOL_OPTIONS"
  JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS%-javaagent*jayatanaag.jar*}${JAVA_TOOL_OPTIONS#*jayatanaag.jar}"
fi

# ---------------------------------------------------------------------
# Run the IDE.
# ---------------------------------------------------------------------
LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JAVA_BIN" \
  ${AGENT} \
  "-Xbootclasspath/a:$IDE_HOME/lib/boot.jar" \
  -classpath "$CLASSPATH" \
  ${VM_OPTIONS} \
  "-XX:ErrorFile=$HOME/java_error_in_STUDIO_%p.log" \
  "-XX:HeapDumpPath=$HOME/java_error_in_STUDIO.hprof" \
  -Didea.paths.selector=AndroidStudio3.2 \
  "-Djb.vmOptionsFile=$VM_OPTIONS_FILES_USED" \
  ${IDE_PROPERTIES_PROPERTY} \
  -Didea.platform.prefix=AndroidStudio -Didea.jre.check=true \
  com.intellij.idea.Main \
  "$@"
 
Hi laufdi,

i tried your way, that is :
In the "Project Structure" Settings disable "use embedded JDK" and set it to
/usr/local/openjdk8 (in my case).

The message Waiting for build to finish takes foreven, so, following this post, I pushed "Synch project with gradle files" and some compilation started.

But, on the build window, at the bottom right i see the error message "Unknown Platform FreeBSD".

Clicking around i see the trace:
Code:
Caused by: java.lang.IllegalStateException: Unknown platform 'FreeBSD'
    at com.android.build.gradle.internal.res.Aapt2MavenUtils.getAapt2FromMaven(Aapt2MavenUtils.kt:121)
    at com.android.build.gradle.internal.res.Aapt2MavenUtils.getAapt2FromMaven(Aapt2MavenUtils.kt:100)
    at com.android.build.gradle.internal.res.Aapt2MavenUtils.getAapt2FromMavenIfEnabled(Aapt2MavenUtils.kt:79)
...

Which seems related to whan you mention here:
I have a single problem: I have to disable aapt2 and use aapt instead (by setting
android.enableAapt2=false in the project's gradle.properties file), which is not any more possible with gradle later than 4.1. Maybe someone has an idea about this?
[\QUOTE]

Then, i tried to change the Java to Linux/Oracle but i get a totally different error message:
Code:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.6/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------

bye
n.
 
Yes I think one not only has to avoid aapt2 but also newer gradle versions and plugins. Newer versions seem to detect the Platform.
The last gradle plugin that works for me is 3.0.1 (not 3.2.1), and gradle 4.1.
-> classpath 'com.android.tools.build:gradle:3.0.1' in build.gradle

Also the last aidl of the build tools that works is that of version 27.0.1, so I copied/linked that into the 28.0.3 dir. Probably due to a bad linux-ldconfig

To avoid all this might be an idea to use a linux jdk but I never tried that (yet) ...

... and very often after changing these values you have to Build->clean or File->invalidate caches/restart
 
laufdi , I guess i will try to get the thing to work with the Linux JDK and make AndroidStudio think it is running under Linux. I think this is the only way i can hope to get the stuff to work in reasonable time.

Also, If we try to avoid new software we will get into new problems very soon. AndroidStudio changes too fast.

bye
n.
 
I have tried the procedure. it takes some hours.

in short, it works, in the sense that after applying it Android Studio starts up.

There are two problems in the the procedure:

1] (minor) it is supposed you installed the linux compatibility layer, see chapter 10 of the
FreeBSD handbook for that.

2] The patch file for the Java code is not available for download, you will need to do the modifications by hand.
It is not a big deal, just 4 lines to add in total. They are trivial code lines.

Other problems:
After starting Android Studio complains that:
1] OpenJDK shows intermittent performance and UI issues. We recommend using the Oracle JRE/JDK.
2] External file changes sync may be slow: Native file watcher is not supported on this platform

My Samsung Glaxy Note 8 broke on day 31 Dec, I am using an old dino-phone which
is not recognized in AndroidStudio, I am reluctant in making further experiments untill i will have a new
phone.

Up to now, i was NOT ABLE to compile and run on phone a simple "hello world" program, that
will require further experiments. I am running FreeBSD in a VM so i must take care of some extra
details. Maybe, running FBS on metal, after the patch it all works, i can't say by now.

Hope it helps quanquan
bye
n.
thanks, i have run the sdk with gradle,but only aapt success, but the aapt2 failed.
i run the ndk tools too, but at last,sdk and ndk sticked by linux compat, glibc2-17
i tryed many linux binary on freebsd,but at last beated by the very old linux kernel support
will freebsd update the linux compat layer?
 
I have tried for serveral hours today to run AndroidStudio completely under the Linux compatibility layer.
That is, without Jacques Fourcy patch.

The good news is that, the system seems to work, running it over and over and over, it seems
that all functionality are there. BUT, there is something bad that i am missing, the thing crashes,
frequently and with a lot of variability.

I used different realeases of the Oracle JDK,
----
jdk-11.0.1_linux-x64_bin.tar.gz => forget about this, it was just a test
jdk-8u191-linux-x64.tar.gz
jdk-8u192-linux-x64.tar.gz
-----

The net result was that i had the most ugly bugs popping out in the afternoon. Examples below.

Bugs change almost every time i run the "studio.sh".

I treid to run "truss" with very limited results.

bye
n.

------- creash Examples --------

====
String index out of range: -1208973864
java.lang.StringIndexOutOfBoundsException: String index out of range: -1208973864
at java.lang.String.substring(String.java:1960)
at java.lang.String.subSequence(String.java:2003)
at java.util.regex.Pattern.split(Pattern.java:1216)
====

====
java.lang.RuntimeException: com.intellij.ide.plugins.PluginManager$StartupAbortedException: Fatal error initializing 'com.android.tools.idea.AndroidInitialConfigurator'
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:212)
at com.intellij.idea.MainImpl$1.lambda$null$0(MainImpl.java:49)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
=====

=========
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000000000000, pid=2320, tid=0x000000083a910700
#
# JRE version: OpenJDK Runtime Environment (8.0_152-b06) (build 1.8.0_152-release-1136-b06)
# Java VM: OpenJDK 64-Bit Server VM (25.152-b06 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C 0x0000000000000000
=====
 
I ran studio with the original script and linux-oracle-jdk10-10.0.2:
(tried also with the studio-jre which crashes)

JDK_HOME=/usr/local/linux-oracle-jdk10/ /compat/linux/bin/bash /path/to/android-studio/bin/studio.sh
and it seems to work perfectly, updating platform-tools and emulator.
Could build an apk just like before. (With Use embedded JDK)

1. After installing and running an apk I have problems with adb "ignoring second debugger -- accepting and dropping", maybe solvable. Conflict of linux-adb with server (not working) and freebsd-adb which works.
2. Then I tried to re-enable aapt2 and I get the same error as before (failed to create directory): maybe that helps: https://stackoverflow.com/a/49353901 ?
 
I ran studio with the original script and linux-oracle-jdk10-10.0.2:
(tried also with the studio-jre which crashes)

JDK_HOME=/usr/local/linux-oracle-jdk10/ /compat/linux/bin/bash /path/to/android-studio/bin/studio.sh
and it seems to work perfectly, updating platform-tools and emulator.
Could build an apk just like before. (With Use embedded JDK)

1. After installing and running an apk I have problems with adb "ignoring second debugger -- accepting and dropping", maybe solvable. Conflict of linux-adb with server (not working) and freebsd-adb which works.
2. Then I tried to re-enable aapt2 and I get the same error as before (failed to create directory)
aapt2 problems.....too
 
aapt2 problems.....too
do you have android-studio and your project and home on the same filesystem?
(home because aap2 is being run from ~/.gradle.astudio/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-linux.jar/185f4dc9f946252cc58c50062e38ea0b/aapt2-3.2.1-4818971-linux/aapt2)
I doubt it would help: the failing command only uses android.jar from the sdk (other filesystem). I moved that to home and got the same error.
 
i will not try again, i burnt one week last time. if you try this procedure and it works well, let us know ! i doubt it will work, it is older than this thread, but i am happy to be proven wrong ;)
 
Back
Top