Cannot find namespace 'android'


#1

I am trying to extend the Android activity class to provide onNewIntent handling. I’ve created a new activity and referenced it in the AndroidManifest.xml. When compiling I get a number of errors similar to:

class MainActivity extends android.app.Activity {
app/native/main-activity.android.ts(8,28): error TS2304: Cannot find name 'android'.
protected onCreate(savedInstanceState: android.os.Bundle): void {
app/native/main-activity.android.ts(35,42): error TS2503: Cannot find namespace 'android'.

I’ve followed instructions for tns-platform-declarations with no luck.
I’ve also copied my activity and AndroidManifest.xml file changes into a clone of nativescript-sdk-examples-ng and the types are recognized and compilation works.

Project details:

  • tns --version: 3.1.2
  • tns-android: 3.1.1
  • tns-ios: 3.1.0
  • tns-core-modules: 3.1.0
  • tns-platform-declarations: 3.1.0
  • angular: 4.1.0
  • typescript: 2.3.4

references.d.ts

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

tsconfig.json

{
  "compilerOptions": {
    "noEmitOnError": false,
    "noEmitHelpers": true,
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "noImplicitUseStrict": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "pretty": true,
    "skipLibCheck": true,
    "lib": [
      "es6",
      "dom",
      "es2015.iterable"
    ],
    "baseUrl": ".",
    "paths": {
      "app/*": [
        "app/app/*"
      ],
      "~/app/*": [
        "app/app/*"
      ],
      "*": [
        "node_modules/tns-core-modules/*",
        "node_modules/*"
      ]
    }
  },
  "include": [
    "app/**/*"
  ],
  "exclude": [
    "node_modules",
    "platforms",
    "**/*.aot.ts"
  ]
}

Our project is using the angular-native-seed.


#2

Resolved. The seed project has a gulp task that copies assets from src/ to the NativeScript recognized app/ directory. The references.d.ts file was at the same level as src/ and not getting copied over to app/. Moving the references file inside src/ got it to copy over the tsc isn’t erroring anymore.