Skip to content

Instantly share code, notes, and snippets.

@Jomik
Created July 26, 2019 14:40
Show Gist options
  • Save Jomik/17efba3a26bd3a1e8475006ba25155ca to your computer and use it in GitHub Desktop.
Save Jomik/17efba3a26bd3a1e8475006ba25155ca to your computer and use it in GitHub Desktop.
with import <nixpkgs> { config.android_sdk.accept_license = true; };
let
inherit (pkgs) mkShell openjdk;
androidPkgs = androidenv.composeAndroidPackages {
platformVersions = [ "28" ];
abiVersions = [ "x86" "x86_64"];
includeEmulator = true;
};
inherit (androidPkgs) androidsdk;
in mkShell {
JAVA_HOME = "${openjdk}";
ANDROID_HOME = "${androidsdk}";
buildInputs = with pkgs; [
nodejs-10_x
androidsdk
];
}
@Jomik
Copy link
Author

Jomik commented Jul 26, 2019

Output of tns doctor

➜ tns doctor
✔ Getting environment information 

There seem to be issues with your configuration.
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 6.0.1 and the latest available version is 6.0.2.
✔ Component tns-core-modules has 6.0.1 version and is up to date.
⚠ Update available for component tns-android. Your current version is 6.0.0 and the latest available version is 6.0.1.
✔ Component tns-ios has 6.0.1 version and is up to date.
✔ Your ANDROID_HOME environment variable is set and points to correct directory.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
✖ WARNING: adb from the Android SDK is not installed or is not configured properly.  
 For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ WARNING: The Android SDK is not installed or is not configured properly. 
 You will not be able to run your apps in the native emulator. To be able to run apps
in the native Android emulator, verify that you have installed the latest Android SDK 
and its dependencies as described in http://developer.android.com/sdk/index.html#Requirements 

✖ Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 28 or later. 
 Run `$ sdkmanager` to manage your Android SDK versions. 

✖ You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=23 <=28'. 
 Run `$ sdkmanager` from your command-line to install required `Android Build Tools`. In case you already have them installed, make sure `ANDROID_HOME` environment variable is set correctly. 

@dermetfan
Copy link

dermetfan commented Mar 30, 2020

Try it like this, fixed these errors for me:

let
  androidsdk = pkgs.androidsdk_9_0.overrideAttrs (oldAttrs: {
    useGoogleAPIs = true;
    includeSystemImages = true;
    includeEmulator = true;
  });
in pkgs.mkShell {
  ANDROID_HOME = "${androidsdk}/libexec/android-sdk";
  # …
}

(nixpkgs 20.09pre218613.ae6bdcc5358)

Upon tns run android I always hit this though:

[nix-shell:/…]$ yarn run tns run android
yarn run v1.22.4
$ …/node_modules/.bin/tns run android
Searching for devices...
Preparing project...
File change detected. Starting incremental webpack compilation...
Starting type checking service...
Using 1 worker with 4096MB memory limit
…
Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Building project...
Gradle build...
         + setting applicationId
         + applying user-defined configuration from /…/app/App_Resources/Android/app.gradle
         + using android X library androidx.legacy:legacy-support-v4:1.0.0
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: /…/node_modules/tns-core-modules-widgets/platforms/android/widgets-release.aar

Execution failed for task ':app:mergeDebugResources'.
error=2, No such file or directory

Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed with exit code 1.
^C

[nix-shell:…]$

Not sure which file it is missing… I'm trying to build the Svelte Native template.

If you have new findings please let me know.

@pietdevries94
Copy link

I figured it out! The easiest way to work around this problem is using buildFHSUserEnv, as documented here https://nixos.wiki/wiki/Android#gradlew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment