Building Unity with Jenkins - Platform directives not defined? - android

I am trying to build my Unity project with Jenkins.
Created a BuildScript with the following calls (not all is shown):
BuildPlayerOptions options = new BuildPlayerOptions();
options.scenes = new string[] { "Assets/game.unity" };
options.targetGroup = BuildTargetGroup.Android;
options.target = BuildTarget.Android;
options.locationPathName = "/Users/Admin/my.apk";
BuildPipeline.BuildPlayer(options);
When I call this build from a local shell, the build works great and an apk is created.
When I try to call it from Jenkins using the Unity3d plugin, I get a strange compilation error which seems to be related to a missing UNITY_ANDROID directive. So basically code inside
#if UNITY_ANDROID
...
#endif
Is not called.
Is there any reason why when my code is compiled from the Jenkins build, the above directive (and others I guess) are not defined automatically?

So I was able to solve this one, by trial and error.
It appears that when I ran the build with a -projectPath, Unity does not recognise the platform and set the directive.
Adding the -buildTarget Android command line to the build, solves this issue.

Related

TypeError: undefined is not an object (evaluating 'argv.indexOf')

I'm running a React Native app which has a local Node project as a dependency, managed through yalc. I'm using rn-nodeify to deal with the Node libraries.
Whenever I try using one of the methods/constants from my Node project, I get the above error during react-native start after the app is built (I'm using Intellij's default "Android" configuration to run RN and have an emulator in Android Studio).
I looked up the error message and people say it's related to supports-color, but neither of my projects use that library and installing it didn't fix it either.
Edit:
I'm not sure if this could be related, but I also have to add the lines
import { Buffer } from 'buffer';
import 'reflect-metadata';
global.Buffer = global.Buffer || Buffer
When I use this file from my Node project or I get errors regarding Reflect.hasOwnMetadata and Buffer

include.gradle file being generated is causing problems

When building a project I get the following error:
Flavor 'nativescript-telerik-ui' has unknown dimension 'nativescript-telerik-ui'.
It happens only when using the pro version through the #progress registry. Doesn't happen with the local .tgz pro version.
I noticed the error has to do with the include.gradle file it generates. I read the following article: https://docs.nativescript.org/plugins/plugins#includegradle-specification
It says that when the plugin doesn't have the include.gradle, at build time gradle creates a default one with default elements. When I saw the include.gradle it generated for the plugin it seems to have generated a default one like so:
android {
productFlavors {
"nativescript-telerik-ui" {
dimension "nativescript-telerik-ui"
}
}
}
The include.gradle generated for the local .tgz version of the plugin is like this:
android {
productFlavors {
"F6" {
dimension "nativescripttelerikuipro"
}
}
}
I replaced the default include.gradle with the latter and it got past the error. You can recreate the problem by following these steps:
create a new hello world app
use the command npm login --registry=https://registry.npm.telerik.com/ --scope=#progress to log in if you're a paying customer.
use the command npm install --save #progress/nativescript-telerik-ui-pro to install the plugin
use tns run android
Is there anything I can do to solve this problem? Really need help on this.
My name is Vladimir and I am part of the nativescript-telerik-ui-pro team. Thank you for logging this issue in our feedback portal. We are going to review it as soon as possible and update you regarding its status, but from what I currently see there is some incorrect "parameters" passed to the 'pro' version of the plugin that are going to be resolved very fast.
We apologize for any inconvenience that this is causing.

Passing -P parameters to gradle from android studio

Is there a functionality inside android studio to do things like this.
Basically my gradle script reads parameter named version based on which it sets dependency version of a certain library.
So when I do gradlew -Pversion=‘1.2.3' I get this string inside gradle. But this only works if I invoke gradle from console.
Is there a way to pass parameters to gradle when started using configuration for project inside Android Studio (pressing little play triangle)?
NOTE:I did find Gradle VM options and Script prameters under default configs but adding -Pversion=‘1.2.3' there doesn't seem to have an effect.
In order to provide parameter to run option of Android Studio you should setup them under AndroidStudios Compile Preferences
AndroidStudio > Preferences...
Under Compiler: ComandLineOptions
Run > Edit Configurations..
Replace "abcdef" in Script parameters by your params.
For example let's try to pass server base endpoint while building project. First we need to define a method which gets url and sets it
def serverUrl = "https://mydefaulturl.com"
task(runProgram){
if(project.hasProperty("url")){
serverUrl = url;
}
}
In your buildTypes create your base url with this value:
debug{
buildConfigField("java.lang.String","BASE_URL","$serverUrl")
}
Now we can pass debug build an url and use it.
You can build your project from terminal with the command below:
./gradlew installDebug task runProgram '-Purl="https://yournewurl.com"'
Put version="1.2.3" in gradle.properties or under
buildscript {
ext{
version="1.2.3"
}
...
}

Android Studio 1.3 - can't debug native

I am using the latest AS from the canary channel, and the ndk that goes with it.
I modified my Android project to suit, and my app (including JNI) builds and runs properly.
I have not (yet) allowed the tools to automatically handle building the JNI part. Lots of special sauce in the existing makefiles, so that would be a lot of work. So I don't have an android.ndk section in my build file. I also have a single gradle.build file.
My debug build type looks like this:
android.buildTypes {
debug {
isMinifyEnabled = false
proguardFiles += file('proguard-rules.txt')
isDebuggable = true
isJniDebuggable = true
}
}
I added a native run configuration. When I try to debug it, I get an exception like LLDB server not found.
If I switch the to gdb, I get a different exception. Any thoughts?
A couple of JNI samples like Teapot and hello-jni are working fine.
Here is the LLDB exception:
LLDB server not found
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:115)
at com.android.tools.ndk.run.lldb.AndroidLLDBDebuggerContext.launchLLDBServer(AndroidLLDBDebuggerContext.java:66)
at com.android.tools.ndk.run.lldb.AndroidLLDBDebuggerContext.startServer(AndroidLLDBDebuggerContext.java:55)
at com.android.tools.ndk.run.AndroidNativeDebugRunner$NativeDebugLauncher.launchDebug(AndroidNativeDebugRunner.java:109)
at org.jetbrains.android.run.AndroidRunningState.launchDebug(AndroidRunningState.java:835)
at org.jetbrains.android.run.AndroidRunningState.clientChanged(AndroidRunningState.java:814)
at com.android.ddmlib.AndroidDebugBridge.clientChanged(AndroidDebugBridge.java:879)
at com.android.ddmlib.Device.update(Device.java:721)
at com.android.ddmlib.Client.update(Client.java:938)
at com.android.ddmlib.HandleAppName.handleAPNM(HandleAppName.java:112)
at com.android.ddmlib.HandleAppName.handleChunk(HandleAppName.java:65)
at com.android.ddmlib.MonitorThread.callHandler(MonitorThread.java:414)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:322)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
I'm afraid you need compile your C++ codes with gradle but not makefile. LLDB server will be generated with gradle automatically. Android studio didn't support any other external build systems(e.g. Makefile) yet.
We have attach the debugger as java not as native. As for you have mentioned ndk it should use native. but any how try this method to avoid debugger detaching and app gets killed automatically.

Build an android apk from Unity3d project working with C/C++ dll

I made a Unity3d project working with C/C++ Dll.
So first I made the dll in Visual studio.
// mydll.cpp
#define EXPORT_API __declspec(dllexport)
extern "C" {
int EXPORT_API add(int a, int b)
{
return a+b;
}
}
And I added this dll into my Unity3D project and called
// C# script in Unity3D
public class TestDll : MonoBehaviour {
[DllImport("mydll")]
private static extern int add (int a, int b);
void Start() {
int a = add (100, 200);
}
}
This code works well and I got the correct result in Unity3D editor.
So I built this project to android platform and got an apk.
I installed and run this apk on my android device but the app doesn't work.
The app didn't run the Dll function.
Whats the matter? I tried to find out the solution in Google and here, but didn't get anything, yet.
Please help me.
Thanks.
Your dll must be in Plugins folder for Windows, it can work for Editor too. for Android you must replace in Plugins/Android folder. Build and write me ok
LearnCocos2D's comment is accurate.
To get Unity to DllImport() a shared library on Android, you must use an NDK compiler and specify a compile config for your target Android platform. Moreover, Unity requires you to specify the architecture of the Android platform in the build settings, eg.. "arm v7" vs "arm64".
As an aside, in Unity 2019.4 - selecting "Load on Startup" in the inspector page of my .so elicits a "DLLNotFoundException".
Overview of this: https://docs.unity3d.com/2019.4/Documentation/Manual/AndroidNativePlugins.html
NDK's CMake guide for getting you started on compiling correctly: https://developer.android.com/ndk/guides/cmake

Categories

Resources