Apple announced it is building its first R&D centre in China, with plans to complete the project by the end of the year.

Apple CEO Tim Cook made the announcement during a recent visit, his second since May. He met with Vice Premier Zhang Gaoli.

The R&D centre will house its operations and engineering teams and will expand its ties with partners and universities, Reuters said.

The Cupertino-based company has more than 9,000 employees in China, with about half working at its 42 retail stores.

Apple’s fortunes have soured in China, its second largest market, where demand for iPhones has dropped sharply this year and it has faced a series of legal and regulatory hurdles that continue to weaken its competitive position in the country.

Its revenue in Greater China, which includes Hong Kong and Taiwan, plunged 33 per cent to $8.8 billion in its fiscal Q3 ending 30 June. Its smartphone market share dropped to 10.8 per cent in May, putting it in fifth place, according to Counterpoint Research. The iPhone’s market share was 17.8 per cent in Q1 2015, when it was the top-ranked smartphone vendor in China.

Cook’s charm offensive in May, when he met with high-level Chinese officials in Beijing, hasn’t appeared to improve its relations with the government, despite its $1 billion investment in Chinese ride-hailing app Didi Chuxing, the single largest investment the company has received.

Its latest setback came in June when Beijing’s intellectual property regulator ruled that the design of some of Apple’s iPhone models infringed on an exterior design patent held by a previously unknown Chinese firm.