Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17911] Windows: Implement Native module support

GitHub Issuen/a
TypeEpic
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-06-12T13:30:06.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.1.0
ComponentsWindows
Labelsmerge-3.4.2
ReporterIngo Muschenetz
AssigneeGary Mathews
Created2014-10-24T22:02:06.000+0000
Updated2017-03-31T22:01:29.000+0000

Description

This encompasses a few sub-items: * Prove that we can build ti.cloud, ti.map and ti.facebook-type modules * Create a default project structure for new modules * Add CLI tooling to create these modules * Hook up Studio to create new module projects.

Comments

  1. Christopher Williams 2015-05-07

    [~gmathews] Please open up a handful of tickets to roughly correspond to steps we'd need to take to support native modules/DLLs for Windows similar to how we would for iOS/Android. This will likely involve work on the CLI/build to reference the modules and link them up during the build.
  2. Jörgen Buder 2016-04-04

    Hi I need to create a couple of modules for Windows Phone support and it seems the direct API access sis not working for me in this case, so how do I create the module you have resolved above? I cannot find any docs o this.. thanks Any module template and CLI commands needed to build and hook in the module would be fine (we have created natives for iOS and Android so I get the general picture here ) thanks
  3. Fokke Zandbergen 2016-04-04

    [~bimmel] Can we document how to build and use modules for Windows as part of the Windows-focussed 5.3 release?
  4. Jörgen Buder 2016-04-05

    Hi I have tried basically everything now, from using the build script to trying the build command line from the github repo of Windows describing how to set up and create a module, nothing really results in a module useable. If I use the terminal build line like this: Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\extwin2\windows>ti build --platform windows --target wp-emulator --device-id 8-1-1 --win-publisher- id 00000000-0000-1000-8000-000000000000 I get a zip file but it only contains a hip file the rest is skipped and not even build. If I try to use the ./build_and_test.sh the project seems to build but there is not modules/ tree or zip file I can use to include in my project, is you can please let me know here asap how to do this I can write you new docs on this that you can get into the github repo or docs, just give me a hint on how to do this. If you have time Fokke, please try this out, I use Phone 8.1 and the latest CLI.. I created the module with : Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\extwin2\windows>ti build --platform windows --target wp-emulator --device-id 8-1-1 --win-publisher- id 00000000-0000-1000-8000-000000000000 if I do not supply the name and id then the entry test crashes... so this was the only way.. thanks guys
  5. Kota Iguchi 2016-04-05

    There's a useful Q&A in Stack Overflow: [How to call a method added to the windows native module of Appelerator Platform](http://stackoverflow.com/questions/36213930/how-to-call-a-method-added-to-the-windows-native-module-of-appelerator-platform/36214120#36214120) However we don't have any document about this yet. I'll file a new ticket for this.
  6. Jörgen Buder 2016-04-05

    Unfortunately the stack overflow does not work either unless you just updated it. It does not tell the correct way, it references to the github repo witch states things not needed anymore, like the cloning of ti windows, and git submodule update that do not work. Creating a module is also very hard as the CLI does not take entry, I had to put name and id as variables. Also then building is not clear, do I build as in the gitrepo or as in the ./build_and_test script, either way no one generates a valid zip module to be used. The command line build in github gives only a empty module zip file without any dll or lib, the build script builds but do not generate any zip file Any suggestions o how to get from build script to useful module ? Also I do not know as states in the stack overflow exactly where to put the function description that you mentioned last. I will have a look at the SDK but I will have to do that later... ANY help just to get this up and running is great and I can help writing docs.. /Jörgen
  7. Kota Iguchi 2016-04-05

    I remember following CLI command worked for me. I'll give it a try again and create new ticket if it has issues.
       cd MY_WORKSPACE
       ti create -p windows -t module
       cd MY_MODULE_NAME/windows
       ti build -p windows -T ws-local
       
  8. Jörgen Buder 2016-04-05

    I tried exactly this, did not work at all, or let me refrase, it constructs a zip file but it is useless as it only contains the hpp file, there is no building taking place... :(
  9. Jörgen Buder 2016-04-05

    Name = Microsoft Windows 8.1 Pro Version = 6.3.9600 Architecture = 32bit # CPUs = 4 Memory = 4294488064 Node.js Node.js Version = 0.12.7 npm Version = 2.11.3 Titanium CLI CLI Version = 4.1.0-dev Titanium SDK SDK Version = 5.2.1.GA SDK Path = C:\Users\jorgenbuder\Library\Application Support \Titanium\mobilesdk\win32\5.2.1.GA Target Platform = windows Command node C:\Users\jorgenbuder\AppData\Roaming\npm\node_modules\titanium\bin\titani um build -p windows -T ws-local --- WindowsModuleBuilder loginfo [INFO] Visual Studio version: 12.0 [INFO] MSBuild version: 12.0.31101.0 [INFO] Project directory: Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Wo rkspace\extwin2\windows [INFO] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsPhone.ARM\ComTestwinSe.sln [INFO] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsPhone.Win32\ComTestwinSe.sln [INFO] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsStore.ARM\ComTestwinSe.sln [INFO] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsStore.Win32\ComTestwinSe.sln [DEBUG] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsPhone.ARM [DEBUG] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsPhone.Win32 [DEBUG] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsStore.ARM [DEBUG] Skipping Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\ex twin2\windows\WindowsStore.Win32 [INFO] Creating zip: com.testwin.se-windows-1.0.0.zip [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\assets\\README" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\documenation\\index.m d" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\example\\app.js" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\include\\ComTestwinSe .hpp" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\LICENSE" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\manifest" [DEBUG] Packing: "modules\\windows\\com.testwin.se\\1.0.0\\timodule.xml" [INFO] Done. Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\extwin2\windows>
  10. Kota Iguchi 2016-04-06

    [~buder] Thanks you for the logs. Looks like nothing is built on your environment. Could you run it with trace log enabled? ti build -p windows -l trace -T ws-local.
  11. Jörgen Buder 2016-04-06

    Please note that when I run the ./build_and_test script from command line it builds the full module project on Windows, but sure I will try it /Jörgen
  12. Jörgen Buder 2016-04-06

    With trace on, exact same output :(
  13. Kota Iguchi 2016-04-06

    [~buder] I see your Visual Studio project is built using Documents directory Z:\Users\jorgenbuder\Documents\Appcelerator_Studio_Workspace\extwin2\windows\WindowsPhone.Win32, but Windows temporary directory should have been used in the latest Titanium CLI. (i.e. C:\Users\jorgenbuder\AppData\Local\Temp\com.testwin.se\). Could you update your CLI? I usually do like below to update CLI and SDK:
        $ appc setup
        $ npm install -g titanium
        $ ti sdk install -b master -d
        
    And then
        cd MY_WORKSPACE
        ti create -p windows -t module
        cd MY_MODULE_NAME/windows
        ti build -p windows -T ws-local -l trace
        
  14. Jörgen Buder 2016-04-06

    With the script that I mention I have a full build folder with a windows visual project... don´t know if this helps.. /Jörgen
  15. Jörgen Buder 2016-04-07

    So after these updates, I think (not sure) I was able to build and package a module, however now my environment can´t build and/or deploy the app to my emulator or device anymore. This worked perfectly until after this upgrade, do you know why this might be. Please consider that I am in critical production of the app and have a dead line. I use the Emulator 8.1. First I got a strange deploy error, but now after reboot Windows I got this , which surprise me as the folder is not a standard build folder, is this cleaned for real when I clean the project ? Everything is now different , Please help [TRACE] : C:\Program Files (x86)\Windows Kits\8.1\\bin\x86\MakePri.exe Dump -IndexFile "Z:\Users\jorgenbuder\Library\Application Support\Titanium\mobilesdk\win32\5.4.0.v20160406002717\windows\lib\TitaniumWindows_Ti\phone\x86\TitaniumWindows_Ti.pri" -OutputFile ERV.dir\Release\TitaniumWindows_Ti.pri.xml -ExtensionDll "C:\Program Files (x86)\Windows Phone Kits\8.1\\bin\x86\MrmEnvironmentExtDl.dll" -Verbose -Overwrite [DEBUG] : _CreatePackageLayout: Removing directory "ERV.dir\Release\PackageLayout\". [TRACE] : Done Building Project "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj" (default targets) -- FAILED. [ERROR] : C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(1986,9): error MSB3231: Unable to remove directory "ERV.dir\Release\PackageLayout\". The directory is not empty. [C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(1986,9): error MSB3231: [C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj] [TRACE] : Done Building Project "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj.metaproj" (default targets) -- FAILED. [TRACE] : Done Building Project "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.sln" (default targets) -- FAILED. [DEBUG] : Build FAILED. [TRACE] : "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.sln" (default target) (1) -> "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj.metaproj" (default target) (2) -> "C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj" (default target) (6) -> [ERROR] : (_CreatePackageLayout target) -> C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(1986,9): error MSB3231: Unable to remove directory "ERV.dir\Release\PackageLayout\". The directory is not empty. [C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(1986,9): error MSB3231: [C:\Users\jorgenbuder\.titanium\vsbuild\gws\phone.x86\ERV.vcxproj] 0 Warning(s) 1 Error(s) /Jörgen
  16. Jörgen Buder 2016-04-07

    I can also see that the tiapp.xml does not accept this: com.test.se the windows tag is not enumerated, and it says it supports: Andorid, iPad, iPhone, ivi (?) , and Tizen and mobileweb and commonjs How do I add the module to the tiapp.xml ? thanks
  17. Jörgen Buder 2016-04-07

    Solved it, I had to remove the OLD run targets for both device and emulator At this point I will now try to enhance the module with some function that returns native data like simony and also to generate the key I need for API encryption.. Thanks so far!!
  18. Jörgen Buder 2016-04-11

    Hi I have been able to enhance the module with a function now as well, but have small trouble to understand how to parse the argument coming in , it is sometimes used as this:
         TITANIUM_ASSERT(argument.IsObject());
        TITANIUM_ASSERT(argument.IsString());
        
    but I have no way to parse it for use, any example that I can use from the SDK, I can´t get it to work properly and would like to use the plain FUNCTION...
        TITANIUM_FUNCTION(Extendwindows, createNotification)
        	{
        	    
        	    TITANIUM_ASSERT(argument.IsObject());
        	    TITANIUM_ASSERT(argument.IsString());
        	    TITANIUM_LOG_DEBUG("Extendwindows:: called createNotification()");
        	    
        	    //return get_context().CreateBoolean(true); // Works
        	    return get_context().CreateNumber(500); // Works
        	    //return get_context().CreateString("Hello"); // Works 
        	    //return get_context().CreateUndefined(); // Works
        	}
        
        TITANIUM_FUNCTION_DEF(genKey);
        			TITANIUM_FUNCTION_DEF(getValues);
        			TITANIUM_FUNCTION_DEF(createNotification);
        	};
        
    Also the loggs do not work even if I am in emulator... any additional help is much appreciated
  19. Christopher Williams 2016-04-11

    The TITANIUM_ASSERT macros don't convert the argument, just confirm it's of a given type (and if not, will log an error). If you're looking for examples on how to write native code, our source for the whole SDK is available and would be beneficial to look over. But here's a quick example: https://github.com/appcelerator/titanium_mobile_windows/blob/master/Source/UI/src/TextField.cpp#L358
        TITANIUM_ASSERT(argument.IsString() || argument.IsNumber());
        layoutDelegate__->set_minWidth(static_cast<std::string>(argument));
        return true;
        
    Here we are asserting that the argument is a JS String or Number, and we are converting it to a C++ std::string before passing it into a method call in C++. So in your case, I'm not sure what exactly you're looking to do, but maybe this is a start:
        TITANIUM_FUNCTION(Extendwindows, createNotification) {
        	TITANIUM_ASSERT(argument.IsString());
        	TITANIUM_LOG_DEBUG("Extendwindows:: called createNotification()");
        	auto msg = static_cast<std::string>(argument); // cast the JS String to a c++ std::string
        	// do something with the std::string...
        	return get_context().CreateBoolean(true); // return a boolean indicating success?
        }
        
    Typically we use the assert to ensure our cast later doesn't fail in some non-obvious way to the user.
  20. Jörgen Buder 2016-04-11

    return get_context().CreateString(static_cast(argument)); I have short with time right now, but I tried the above in my function and it crashed because the "argument" variable did not exist, it seems similar to what you propose and I am not sure that works, will try it but as I said the variables "argument" is not available outside the ASSERT. ?
  21. Christopher Williams 2016-04-11

    Sorry, I didn't look close enough, you're doing a function - not a property setter. For a property getter, there is no argument; for a property setter, there's a single argument in a variable named "argument"; for a function there's an array of arguments in a variable named "arguments".
        TITANIUM_ASSERT(arguments.size() == 1);
        auto _0 = arguments.at(0);
        TITANIUM_ASSERT(_0.IsString());
        auto msg = static_cast<std::string>(_0);
        
  22. Jörgen Buder 2016-04-14

    Gary, It turns out the module that are created have a lot of local references, it means that I am not able to share the module with other developer because lots of file references go to my user and computer, can I somehow clean this up and regenerate this meta data so that it builds on other machine? All modules in iOS and Android can be build with any user/machine/environment Example: CMakeLists.txt :

    Titanium Windows Native Module - extendwindows

    #

    Copyright (c) 2015 by Appcelerator, Inc. All Rights Reserved.

    Licensed under the terms of the Apache Public License.

    Please see the LICENSE included with this distribution for details.

    cmake_minimum_required(VERSION 3.0.0) if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsPhone") set(PLATFORM wp) add_definitions("-DPHONE") elseif(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore") set(PLATFORM store) else() message(FATAL_ERROR "This app supports Store / Phone only.") endif() project(GwsExtendwindows) set(GwsExtendwindows_VERSION 0.1.0) set(WINDOWS_SOURCE_DIR "Z:/Users/jorgenbuder/Library/Application Support/Titanium/mobilesdk/win32/5.4.0.v20160406002717/windows") SET(CMAKE_FIND_LIBRARY_PREFIXES "") SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")
  23. Lee Morris 2017-03-31

    Closing ticket as fixed, if there are any problems, please file a new ticket.

JSON Source