I have a issue when trying to build Android version in Unity3d - java

I have tried building my app in Unity3d in both Gradle and Internal but both times I get errors at the end of building processes. I also have some plugins in my app so I tried changing SDK and made sure all the plugins are imported into my assets but that didn't help.
Error when build system is Gradle:
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_181\bin\java.exe -classpath
"C:\ProgramFiles\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\
gradle\li
b\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-
Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
stderr[
Note: C:\Users\Hendrik\Desktop\POOWA-
master\Temp\gradleOut\src\main\java\com\google\unity\ads\Banner.java uses or
overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]:
65536
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.
* Get more help at https://help.gradle.org
Error when build system is Internal:
CommandInvokationFailure: Failed to re-package resources.
E:\sdkandroid\build-tools\27.0.3\aapt.exe package --auto-add-overlay -v -f -
m -J "gen" -M "AndroidManifest.xml" -S "res" -I
"E:/sdkandroid\platforms\android-28\android.jar" -F bin/resources.ap_ --
extra-packages
These are not complete errors, but I think these still should show what's wrong. I could also provide more if needed.

Have you tried this?
Android environment setup
Whether you’re building an Android application in Unity or programming it from scratch, you must set up the Android Software Development Kit (SDK) before you can build
and run any code on your Android device.
Install the Java Development Kit
Download and install the Java Development Kit (JDK). Unity requires the 64-bit version JDK 8 (1.8).
Download the Android SDK
You can install the Android SDK using command line tools orthrough Android Studio. Android Studio provides an easy to use GUI based tool, but installs additional software on your computer. Using the command line tools is a smaller download and does not install additional software, but it can be more challenging to use.
2a. Install the Android SDK using the command line tools
Install or unpack the Android SDK. After installing, open the Android SDK Manager and add: at least one Android SDK Platform, the Platform Tools, the Build Tools, and the USB drivers if you’re using Windows.
To install an Android platform SDK and the associated tools:
Download the Android Software command line tool.
Unzip the tools folder to a location on your hard drive.
Open a command-prompt window.
Navigate to the bin folder in the location where you unzipped the tools folder: “install folder” > tools > bin
Use the sdkmanager command line tool to retrieve the list of packages that you can install. The installable packages include the Platform SDKs, Build Tools, Platform tools, and other tools.
sdkmanager –list
Select a version of the Platform SDK to install. Platform SDKs take the following form in the list: platforms;android-xx. The xx indicates the SDK level. The larger the number, the newer the package. Typically, you can install the latest available version. But, there might be cases in which Google has released a new version of the SDK that causes errors when you build your Unity Project. In that case you must uninstall the SDK and install an earlier version. The general format of the command for package installation is sdkmanager . You can install the corresponding Platform Tools and Build Tools at the same time.
Example: sdkmanager “platform-tools” “platforms;android–27” “build-tools;27.0.3”
If you are running on Windows, install the USB device drivers.
sdkmanager “extras;google;usb_driver”
This installs the SDK in a directory named “platforms” in the directory in which you unzipped the tools folder. Example: c:\\platforms
2b. Install the SDK using Android Studio
Install Android studio from the Android developer portal. The Android developer portal provides detailed installation instructions.
When installing the Android platform SDK and other tools, you can typically install the latest available version. There might be cases in which Google has released a new version of the SDK that causes errors when you build your Unity Project. In that case you must uninstall the SDK and install an earlier version.
Install the associated Platform and Build tools at the same time. If you are running on Windows, install the USB device drivers.
Enable USB debugging on your device
To enable USB debugging, you must enable Developer options on your device. To do this, find the build number in your device’s Settings menu. The location of the build number varies between devices. The stock Android setting can be found by navigating to Settings > About phone > Build number. For specific information on your device and Android version, refer to your hardware manufacturer.
Build number as displayed in Android 5.0 (Lollipop) on a Samsung Galaxy Note 3
Build number as displayed in Android 5.0 (Lollipop) on a Samsung Galaxy Note 3
Note: On Android versions prior to 4.2 (Jelly Bean), the Developer options aren’t hidden. Go to Settings > Developer options, then enable USB debugging.
After you navigate to the build number using the instructions above, tap on the build number seven times. A pop-up notification saying “You are now X steps away from being a developer” appears, with “X” being a number that counts down with every additional tap. On the seventh tap, Developer options are unlocked.
Connect your device to your computer using a USB cable. If you are developing on a Windows computer, you might need to install the a device specific USB driver. See the manufacture web site for your device for additional information.
The setup process differs for Windows and macOS, and is explained in detail on the Android developer website. For more information on connecting your Android device to the SDK, refer to the Running Your App section of the Android Developer documentation.
Go to Settings > Developer options, and check the USB debugging checkbox to enable debug mode when the device is connected to a computer via USB.
Developer options as displayed in Android 5.0 (Lollipop) - Samsung Galaxy Note 3
Developer options as displayed in Android 5.0 (Lollipop) - Samsung Galaxy Note 3
4. Configure the Android SDK path in Unity
The first time you create a Project for Android (or if Unity later fails to locate the SDK), Unity asks you to locate the folder in which you installed the Android SDK.
If you installed the SDK using the sdkmanager, you can find the folder in \platforms\.
Example:
c:\\platforms\android–27
If you installed the SDK when you installed Android Studio, you can find the location in the Android Studio SDK Manager. To open the SDK Manager from Android Studio, click Tools > Android > SDK Manager or click SDK Manager in the toolbar.
SDK Manager toolbar button
SDK Manager toolbar button
To change the location of the Android SDK, in the menu bar go to Unity > Preferences > External Tools.
Download and set up the Android NDK
If you are using the IL2CPP
scripting backend
for Android, you need the Android Native Development Kit (NDK). It contains the toolchains (such as compiler and linker) needed to build the necessary libraries, and finally produce the output package (APK). If you are not targeting the IL2CPP back end, you can skip this step.
Download Android NDK version r13b (64-bit) from the NDK Downloads web page. Extract the android-ndk folder to a directory on your computer and note the location.
The first time you build a Project for Android using IL2CPP, you are asked to locate the folder in which you installed the Android NDK. Select the root folder of your NDK installation. To change the location of the Android NDK, in the Unity Editor, navigate to the menu: Unity > Preferences to display the Unity Preferences dialog box. Here, click External Tools.

Related

How to resolve the issue "Failed to install the following Android SDK packages as some licences have not been accepted."?

This is a very unnecessary issue, but here it goes.
I want to compile and run a few months old react native app. It runs flawlessly before just by a single command-line script call.
At the moment, it is stuck here:
A problem occurred configuring project ':react-native-reanimated'.
> Failed to install the following Android SDK packages as some licenses have not been accepted.
patcher;v4 SDK Patch Applier v4
emulator Android Emulator
tools Android SDK Tools
platforms;android-28 Android SDK Platform 28
build-tools;29.0.2 Android SDK Build-Tools 29.0.2
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
I look around and found that I have to accept it using sdkmanager.
I have tried to accept the licenses using `SDK manager, but it gave me "Xmlscheme error".
I look around and found that this is caused by my JDK being too new (version 15). So I degrade it to JDK 8.
Now the sdkmanager can launch, and it immediately shows:
All SDK package licenses accepted.======] 100% Computing updates...
Now I tried to run the build script again, but the previous license acceptance error is still there.
Some answers said that it was probably because I don't have the privilege to change it, and suggest changing it using chmod 0777 on the SDK folder. I have done that. Rerun the accepting license. Rerun the build script. Still the same.
How can I fix this? SDK manager doesn't even show any license that isn't accepted. All is already accepted.
Update: I run ./sdkmanager --licenses --verbose, and it looks like every time it tries to accept licenses and it report accepted, but if I run again, it accepts the same licenses. Like... the accept result is not saved.
Update: From this comment, I have tried sdkmanager --licenses --sdk_root=~/Library/Android/sdk, and it looks like it's accepting licenses (asking whether want to accept license or not). But after accepting licenses, it's still resulting in the same issue as above.
If you have not resolved this by now, here is the solution:
Go to the Settings in Android Studio
Go to Android SDK
Select SDK Tools tab
Mark and install the following packages: "Android SDK Command-line Tools", "Google Play Licensing Library" and optionally (as I am not sure whether it is necessary) "Google Play Services"

Can not set the path of NDK in project structure in Android studio

I am using the latest version of Android studio V4.1 to implement my project on Windows 10.
The project also requires Java 11 and Ndk libraries.
First, I installed NDK V22 and V16 as well as Cmak from SDK tools in SKD manger as shown below:
Then, Installed Java 11 from Oracel.com, and checked using cmd as shown below:
I added the paths of SDK and NDK to the local.properties files as follows:
sdk.dir=C\:\\Users\\user_name\\AppData\\Local\\Android\\Sdk
ndk.dir=C\:\\Users\\user_name\\AppData\\Local\\Android\\Sdk\\ndk\\22.0.7026061
Also, added JAVA_HOME and ANDROID_NDK_HOME in the system environment.
The problem is that I can not locate the NDK path from the "File > project structure> Android NDK location" in the Android project to tell the Android studio where is the NDK is located. It always shows as inactive and can not browse the path as shown in the below picture:
Info:
Android Gradle Plugin Version 4.1.1
Gradle Version 6.8
Can anyone help to fix this problem?
This was moved to the build.gradle to keep builds reproducible: https://developer.android.com/studio/releases/gradle-plugin#ndk-path
It's not in the UI because you should almost never use it. You should be using android.ndkVersion in almost all cases. android.ndkPath (and ndk.dir) is just a way to make builds non-reproducible/non-portable.
The cases where android.ndkPath makes sense are if your CI service only has the NDK installed to a specific location not known to the SDK, or if you're using an unreleased NDK.

Android SDK license issue prevents build of LibGDX project in IntelliJ

After reinstalling Windows 10, I am desperately trying to get my LibGDX project to run in IntelliJ again. It will not build because of an Android SDK license issue.
I reinstalled Android Studio and the Android SDK 27, which I had been using in my project before, but I got the following error message:
A problem occurred configuring project ':android'.
Failed to install the following Android SDK packages as some licences have not been accepted.
platform-tools Android SDK Platform-Tools
patcher;v4 SDK Patch Applier v4
platforms;android-27 Android SDK Platform 27
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
emulator Android Emulator
tools Android SDK Tools
I found the following thread with lots of suggested fixes:
"Failed to install the following Android SDK packages as some licences have not been accepted" error
So I learned that I have to run
%ANDROID_HOME%/tools/bin/sdkmanager --licenses
It did not work at first because the file /users/MYUSERNAME/.android/repositories.cfg was missing. I created an empty file at that path, ran sdkmanager again and accepted all licenses. However, I still get the same error when building my LibGDX project in IntelliJ.
Here is what I have tried to resolve this issue:
Ran sdkmanager --licenses with administrator priviledges
Ran sdkmanager --update instead of --licenses
Installed the Android command line tools and used that sdkmanager batch file instead
Made sure that the %ANDROID_HOME%\licenses folder exists and contains license files
Made sure that there is not another Android SDK installed on my machine that I am not aware of - both ANDROID_HOME and ANDROID_SDK_ROOT (I read that the former is outdated) environment variables point to the same folder that is also configured as Android SDK location in the Android Studio SDK Manager and as an Android SDK home path in my IntelliJ project settings
Selected the JRE that comes with Android Studio as the standard Java runtime environment on my machine (by setting JAVA_HOME to C:\Program Files\Android\Android Studio\jre)
Uninstalled the API 30 SDK that was automatically installed with Android Studio, so I would only have API 27 left
Tried using the API 30 SDK instead of API 27 by configuring it in the android\build.gradle file of my LibGDX project
Uninstalled Android Studio, removed the SDK folder and reinstalled everything
Added yes | sdkmanager --licenses to my gradlew.bat
None of these seemed to help. When I run sdkmanager --licenses again, the response is
All SDK package licenses accepted.
but IntelliJ keeps saying the opposite.
I am out of ideas how to resolve this. Any help would be highly appreciated.
The issue was most likely due to an incompatibility of the outdated Gradle version with some other dependency, possibly the Android SDK. I resolved it by migrating my project to the newest LibGDX version (1.9.11).
My game would not run with the Gradle wrapper configured in gradle/wrapper/gradle-wrapper.properties (version 5.4.1) because I got another error message ("Could not open cp_init remapped class cache"), so I switched to the latest Gradle version, which is locally installed (6.5.1): Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Use Gradle from: Specified location
I also downloaded the Android API from 30 to 29, as that is the version recommended for use with LibGDX 1.9.11. However, I did not have to use the command line tool to accept the licenses anymore.

NativeScript: Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 22 or later [duplicate]

I've installed NativeScript and I try to do tns platform add android but it doesn't work. ANDROID_HOME path is correct and I have installed SDK (API 22 and the newest one) and tools (25.0.2). When I run tns doctor it says:
WARNING: The Android SDK is not installed or is not configured properly.
Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK 22 or later.
You need to have the Android SDK Build-tools installed on your system. You can install any version in the following range: '>=25.0.2'.
You need to have Android SDK 22 or later and the latest Android Support Repository installed on your system.
The current version of NativeScript 2.5.2 requires certain tools to be in the Android home directory so that it can detect them. The newest version of Android SDK (Mar 2017) actually removed the primary android support file and moved several binary files into other directories to clean things up.
Unfortunately this causes NativeScript to not be able to detect that you have the SDK. This version of the SDK came out AFTER the current version of NativeScript.
The simplest way to fix this that I can think of is to start from the command line; sdkmanager then choose to download the older 25.2.3 tools.
To manually do this; you would need to delete everything in your sdk/tools folder and download:
https://dl.google.com/android/repository/tools_r25.2.3-windows.zip (Windows)
https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip (Macintosh)
https://dl.google.com/android/repository/tools_r25.2.3-linux.zip (Linux)
Then extract these into that sdk/tools directory.
I solved this using the SDK manager in Android Studio, having already installed it previously, install all the requirements, namely
tools,platform-tools,android-25,build-tools-25.0.2,extra-android-m2repository,extra-google-m2repository,extra-android-support
Once installed change your ANDROID_HOME environment variable to point to this SDK manager. Typically, it will be at (/Users//Library/Android/sdk)
export ANDROID_HOME=/Users/<user_name>/Library/Android/sdk
Confirm that NativeScript detects your changes by running
tns doctor

Can I develop Android apps without an IDE?

Is it possible to develop Android apps using only the Android SDK, without any IDE like Android Studio?
Yes, see the Google SDK documentation.
However, with the current toolchain and documentation it'll be an uphill struggle. I'm trying to do this too (for a dev who lives in Vim and Unix tools, Android Studio is needlessly slow and bloated).
The main issues I've found so far:
The SDK documentation gives instructions to create an Ant-driven project, but the SDK is now geared towards using Gradle. If you're working through the Google documentation in a linear fashion, you'll find subsequent lessons have you issue Gradle build instructions. For your Ant-built project.
There is very little documentation on how to actually create a Gradle-built project from the command line. The command line I use is:
android create project --target android-22 --name MyProjectName --path my_project/ --activity MyProject --package com.example.android.myproject --gradle --gradle-version 1.2.2
The --gradle-version actually refers to the Gradle Android plugin version, not the version of Gradle itself. Finding this out wasn't easy.
Even if you get it to create a project properly, it probably won't build without further manipulation. One of the generated files (project/build.gradle) has an invalid directive name (runProguard - I'm guessing it's now deprecated). That must be changed to minifyEnabled before the project will build. And using the Gradle plugin 1.2.2, the file project/gradle/wrapper/gradle-wrapper.properties has the Gradle distribution incorrectly listed as gradle-1.2.2-all.zip. This should be gradle-2.2.1-all.zip.
These are files generated by the SDK with errors.
The documentation is focussed on IDE-based development. Once you get past the initial few pages on creating and managing a project using the command line, it's very IDE-focussed.
Instructions on things like changing an app Theme are difficult or impossible to follow as they omit steps that the IDE performs for you.
In general, fully IDE-less development for Android (at least in Java, using the official SDK) is very painful. And my personal opinion is that IDE-based development is equally painful (slow, bloated, ugly on high-DPI screens under Linux and evidently full of magic that's a pain to replicate on the command line).
Edit: I should add that the above refers to using SDK tools v24.2, SDK Platform-tools v22, SDK Build-tools v22.01 and Android API 22 (5.1.1).
For android the basic debugging environments are:
ADB
DDMS
Java Debugger
You can try with them.
More details are here : http://developer.android.com/tools/debugging/debugging-projects-cmdline.html
Writing an Android app on Notepad is what I do on my Windows Laptop.
First you configure your laptop as follows:
Download development Kits: Download a Java Development Kit 1.6 for Windows and an Android Development Kit . Similarly try downloading older version of Android kit GUI version of Kit Manager so that you can download essentials. Using kit Manager download Android-23 platform build tools. Android Studio may have slower performance, so try to avoid it.
Configure Kits: Set Windows PATH variable by right clicking My Computer -> Properties -> Advanced System Settings or change the appropriate settings in your Control Panel. PATH should include the Java's compiler executable
file in Java directory, and the android.bat file of Android Kit.
Download Build-Tool: (recommended, but Ant can be used too.) These
programs configure the command-line tools for easy usage for our
convenience. I downloaded version 2.2.1 as it can use old
Java & old Android.
I've also written about these instructions on my GitHub Page.
For the development of Android apps one doesn't even need a PC, and not even the Android SDK. One can develop them completely on a mobile Android device, so an emulator isn't necessary either.
For that one needs to the app Termux on the device, and the toolchain script apkbuilder, which stitches together all APK building programs that come with the Termux packages aapt, apksigner, clang, cmake, d8, ecj and unzip, including the OpenJDK.

Categories